spring boot http2

spring boot http2

项目已启动的情况下,启动单元测试报端口has binded

可以使用server.port=-1 禁用端口绑定来启动单元测试

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html#howto-change-the-http-port

http2配置

使用tomcat9 & jdk9+

或者使用tomcat9 & jdk8 with nativelibrary

使用undertow & jdk8+

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html#howto-configure-http2-tomcat

生成证书,配置ssl

https://stackoverflow.com/questions/906402/how-to-import-an-existing-x-509-certificate-and-private-key-in-java-keystore-to
对于已经存在的证书,先把X509格式(证书和私钥是分开的)转换到p12格式(证书和私钥在一个文件里), 使用openssl

openssl pkcs12 -export -in xxxxx.cer -inkey xxxx.key  -out yyyy.p12 -name xxxx

p12格式导入到jdk keystore文件(.jks或者其他文件后缀,它相当于一个打包文件,里面可以包含多个证书和私钥,本身并不是证书)中,使用keytool工具

keytool -importkeystore -deststorepass 123123 -destkeypass 123123 -deststoretype pkcs12 -destkeystore server.keystore -srckeystore yyyy.p12 -srcstoretype PKCS12 -srcstorepass 123123 -alias xxxx

这里生成server.keystore, jdk9之后默认使用的是PKCS12格式的keystore, jks格式是java专用的 不是标准格式

https://docs.spring.io/spring-boot/docs/2.0.0.M6/reference/html/howto-embedded-web-servers.html#howto-configure-ssl

server.port=8443
server.http2.enabled=true
server.ssl.key-store=classpath:server.keystore
server.ssl.key-store-password=123123
server.ssl.key-password=123123

配置模块依赖packageinfo.java?  模块化是jdk的模块化,对于具体maven web应用这个概念不是必须的

验证

使用浏览器验证:访问相关接口,在chrome://net-internals/中查看事件

使用curl验证:

示例:

https://files.cnblogs.com/files/yszzu/spring-http2-demo.zip

posted @ 2018-11-09 16:59  funny_coding  阅读(651)  评论(0编辑  收藏  举报
build beautiful things, share happiness