You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring WebFlux(Netty)开启HTTP/2失败求助:JDK8环境配置问题

Fixing HTTP/2 Support with Spring WebFlux + Netty on JDK 8

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:

  1. Grab the correct alpn-boot version
    The jar version needs to match both your JDK 8 update level and Netty 4.1.24.Final. For JDK 8u191+, the compatible version is 8.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).

  2. 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.jar
    

    Replace the path with the actual location of the jar on your system.

  3. Double-check your Spring Boot config
    Confirm your application.yml has 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:56:55