讓你的spring boot應(yīng)用 支持HTTP2

最近比較流行的http2協(xié)議,在spring boot中可以使用了,昨天看了spring boot 官方文檔?發(fā)現(xiàn)目前只有undertow和tomcat 服務(wù)器才支持而目前spring boot 集成的Tomcat 8.5.x 支持http2稍微麻煩點(diǎn),需要用到?tomcat-native。啟動(dòng)的時(shí)候要加上?-Djava.library.path=/usr/local/opt/tomcat-native/lib? 不然會(huì)報(bào)錯(cuò)

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舉例,關(guān)鍵配置如下:

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


然后寫(xiě)一個(gè)Controller,借助google瀏覽器的一個(gè)插件就可以檢測(cè)你搭建的http2是否成功了


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容