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

如何在spring-cloud-starter-function-web上配置QUIC/HTTP3服务?

在spring-cloud-starter-function-web中配置QUIC/HTTP3服务器

spring-cloud-starter-function-web 依赖 Spring Boot 的 Web 容器实现QUIC/HTTP3支持,以下是具体配置步骤:

1. 确认依赖版本

确保使用支持HTTP3的Spring Boot及Spring Cloud版本:

  • Spring Boot 2.6.x 及以上(推荐2.7.x或3.x)
  • 对应Spring Cloud版本:2021.0.x(Jubilee)及以上

根据你使用的Web容器,添加对应依赖:

若使用Tomcat

在pom.xml中添加:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- Tomcat的HTTP3扩展依赖 -->
<dependency>
    <groupId>org.apache.tomcat.experimental</groupId>
    <artifactId>tomcat-embed-core-h3</artifactId>
    <version>${tomcat.version}</version>
</dependency>

若使用Undertow

替换默认Tomcat依赖为Undertow:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

若使用WebFlux(Reactor Netty)

spring-cloud-starter-function-web也支持WebFlux,此时依赖Reactor Netty的HTTP3支持:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

2. 配置HTTP3参数

在application.yml或application.properties中添加以下配置:

通用SSL配置(必须,QUIC依赖HTTPS)

server:
  ssl:
    enabled: true
    key-store: classpath:keystore.p12
    key-store-password: your-password
    key-store-type: PKCS12
    key-alias: your-alias

本地测试可使用自签名证书,生成命令:

keytool -genkeypair -alias localhost -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keystore.p12 -validity 3650

Tomcat HTTP3配置

server:
  tomcat:
    http3:
      enabled: true
    port: 8443
    http3-port: 8443 # HTTP3与HTTPS可共用端口,Tomcat会自动处理协议协商

Undertow HTTP3配置

server:
  undertow:
    http3:
      enabled: true
    port: 8443

Reactor Netty HTTP3配置(WebFlux)

server:
  port: 8443
  http3:
    enabled: true

3. 验证配置

启动应用后,可通过支持HTTP3的浏览器(如Chrome、Firefox)访问https://localhost:8443/your-function-path,在浏览器开发者工具的「网络」面板中查看协议是否为h3。

也可使用curl命令测试:

curl -I --http3 https://localhost:8443/your-function-path

注意:部分操作系统可能需要额外启用QUIC支持,比如Linux内核需开启相关模块,Windows/macOS需确保浏览器或curl的HTTP3功能已启用。

内容的提问来源于stack exchange,提问作者Douglas Hadjinlian Guerra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 19:07:14