java - Spring Boot 启用 http/2 协议(protocol)

标签 java spring-boot

我正在使用带有嵌入式 Undertow 服务器 1.4 的 Spring boot 1.5.12 (JDK 8),并且我使用“server.https.enabled: true”在我的属性中启用了 http2 协议(protocol),但它似乎不起作用。我还与自签名证书建立了安全连接。当我在浏览器上加载我的应用程序 (Angular 5) 时,我仍然使用 http/1.1 协议(protocol)。

这是我的 SpringBootApplication 类中的内容:

@SpringBootApplication
@EnableEurekaClient
@EnableOAuth2Sso
public class Application extends WebSecurityConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        //some authorization configuration
    }
}

Application.properties 文件

security:
  require-ssl: true
server:
  ssl:
    enabled: true
  http2:
    enabled: true
   port: 8085
    ssl:
      key-store: classpath: keystore.p12
      key-store-type: PKCS12
      key-alias: devel
      key-store-password: pass
      key-password: pass
eureka:
  client:
    serviceUrl:
      defaultZone: https://localhost:8761/eureka
  instance:
    preferIpAddress: false
    securePortEnabled: true
    securePort: ${server.port}

我还需要配置什么吗?

提前致谢

最佳答案

尝试将以下 bean 添加到您的配置中:

@Bean
UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
    UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
    factory.addBuilderCustomizers(
            builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
    return factory;
}

关于java - Spring Boot 启用 http/2 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50470332/

相关文章:

spring-boot - Spring WebFlux Reactive 和 Kotlin Coroutines 启动报错

java - 如果 id 不存在,http put 请求应该返回什么?

java - final 方法中的早期绑定(bind)

java - 一个物理项目中的两个逻辑 java 项目

java - 如何使用可序列化将类对象存储到内部存储器中?

java - File.length() 与 windows 不同,文件内容仍然相同吗?

maven - 在所需端口上运行 spring boot 应用程序的 maven 命令是什么

java - 使用 SnakeYaml 将 java 对象写入文件 - 使用 Yaml.dump() 时不会写出内部对象列表

java - 一次连续向10000个客户端发布数据

java - 如何使用 Selenium 2 单击链接