SpringBoot Http2改造

SpringBoot Http2改造

前置说明

该文档仅说明使用jetty作为web服务器的场景下如何配置
具体springboot有官方的说明文档,链接如下
https://docs.spring.io/spring-boot/docs/2.0.0.RC2/reference/html/howto-embedded-web-servers.html#howto-configure-http2

PS: 文档中有补充说明,基于springboot开启http2,强制要求必须配置ssl

引入依赖

1
2
3
4
5
6
7
8
9
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-conscrypt-server</artifactId>
</dependency>

以上依赖的版本号,统一由spring-boot-dependencies来维护即可

配置ssl

生成ssl文件

1
keytool -genkey -alias jetty -keypass 123456 -keyalg RSA -keysize 1024 -validity 3650 -keystore /Users/littlefisher/Downloads/keystore.jks -storepass 123456

以上内容是为了便于复制,具体配置,可以参考以下链接
keytool(JDK自带)生成ssl证书
文件生成后,放置在springbootresources目录下,以便于springboot配置

springboot配置ssl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server:
# 开启http2
http2:
enabled: true
ssl:
# 证书存放位置
key-store: classpath:keystore.jks
# 证书密码
key-store-password: 123456
# 证书类型
key-store-type: PKCS12
# 协议类型
protocol: TLSv1.2
key-alias: jetty

配置http请求转为http2

TODO: 后续考虑完善

posted @ 2019-07-31 15:52  qxwang  阅读(74)  评论(0)    收藏  举报