Spring WebFlux(Netty)开启HTTP/2失败求助:JDK8环境配置问题
Hey there, let's break down your problem and get HTTP/2 working without jumping to JDK 10. The core issue here is related to ALPN support—let's dive in:
Why HTTP/2 Isn't Activating
JDK 8 doesn't include native support for ALPN (Application Layer Protocol Negotiation), which is a required handshake step for HTTP/2 to work over HTTPS. Even though you've enabled server.http2.enabled and got HTTPS running, without ALPN, your server and client can't agree to use HTTP/2, so they fall back to HTTP/1.1. That's exactly what's happening here.
No Need to Upgrade to JDK 10—Here's the Fix
You can add ALPN support to JDK 8 using Jetty's alpn-boot jar, which patches the JDK's boot classpath to add the required ALPN capabilities. Follow these steps:
Grab the correct
alpn-bootversion
The jar version needs to match both your JDK 8 update level and Netty 4.1.24.Final. For JDK 8u191+, the compatible version is8.1.13.v20181017. Make sure to pick a version aligned with your specific JDK 8 patch level (check Jetty's ALPN compatibility references for exact matches if you're on an older update).Add the JVM bootclasspath argument
Download the jar, then add this parameter when starting your application:-Xbootclasspath/p:/path/to/alpn-boot-8.1.13.v20181017.jarReplace the path with the actual location of the jar on your system.
Double-check your Spring Boot config
Confirm yourapplication.ymlhas these settings correctly set (SSL is mandatory since Spring Boot doesn't support plaintext h2c):server: ssl: enabled: true key-store: classpath:your-keystore-file.jks key-store-password: your-keystore-password key-store-type: JKS http2: enabled: true
Verify the Fix
Once you've applied the patch and restarted your app, test if HTTP/2 is working with a tool like curl:
curl --http2 -I https://your-app-domain:port
Look for HTTP/2 200 in the response—this confirms HTTP/2 is active.
Optional: Upgrade to JDK 9+ (If You Want)
If you're open to upgrading your JDK, JDK 9 and later include native ALPN support, so you won't need the alpn-boot jar at all. But this is totally optional—JDK 8 works perfectly with the fix above.
内容的提问来源于stack exchange,提问作者Roman Dzhadan

