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

基于Netty的Reactive Spring Boot 3.2.2集成Swagger-UI无响应求助

解决Reactive Spring Boot中Swagger UI无法访问的问题

核心问题分析

你使用的是基于Netty的Reactive Spring Boot(WebFlux栈),但引入的是适配Servlet栈(Spring MVC)的springdoc-openapi-starter-webmvc-ui依赖,两者技术栈不兼容,这就是访问Swagger UI无响应的根本原因。

解决方案步骤

1. 替换为WebFlux适配的SpringDoc依赖

移除原有的MVC版依赖,添加WebFlux版本的starter:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
    <version>2.3.0</version>
</dependency>

2. 配置Swagger基础参数(可选但推荐)

在application.yml中添加配置,确保扫描到你的Reactive控制器:

springdoc:
  api-docs:
    enabled: true
  swagger-ui:
    enabled: true
    path: /swagger-ui.html
  packages-to-scan: com.your.package.controller # 替换为你的实际控制器包路径

3. 访问正确的路径

启动应用后,访问以下地址:

  • Swagger UI页面:http://localhost:8080/swagger-ui.html
  • OpenAPI规范JSON:http://localhost:8080/v3/api-docs

关于降级Swagger2无效的说明

Swagger2(Springfox)对Spring Boot 3.x的支持不完善,且同样存在Servlet/Reactive栈的适配差异,Spring Boot 3.x官方推荐使用基于OpenAPI 3规范的SpringDoc OpenAPI,而非旧版Swagger2。

内容的提问来源于stack exchange,提问作者Prajwal Raju P

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 02:47:03