最近比较流行的http2协议,在spring boot中可以使用了,昨天看了spring boot 官方文档 发现目前只有undertow和tomcat 服务器才支持而目前spring boot 集成的Tomcat 8.5.x 支持http2稍微麻烦点,需要用到 tomcat-native。启动的时候要加上 -Djava.library.path=/usr/local/opt/tomcat-native/lib 不然会报错
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
这里我就拿undertow举例,关键配置如下:
application.properties
server.port=8443server.ssl.key-store=classpath:test.dureshangmao.com.jksserver.ssl.enabled=trueserver.ssl.key-password=1063420481server.ssl.key-store-password=1063420481server.http2.enabled=true
pom.xml
然后写一个Controller,借助google浏览器的一个插件就可以检测你搭建的http2是否成功了