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

Spring Boot 3 WebFlux与springdoc OpenAPI 2兼容问题求助

解决思路

1. 移除冲突依赖,保持环境单一

WebFlux和Spring MVC是互斥的,同时引入spring-boot-starter-web和spring-boot-starter-webflux会让Spring Boot默认启用MVC环境,导致WebFlux的自动配置失效,对应的springdoc-openapi-starter-webflux-ui自然无法正常工作。必须删掉implementation 'org.springframework.boot:spring-boot-starter-web'这个依赖,只保留以下两个:

implementation 'org.springframework.boot:spring-boot-starter-webflux:3.0.2'
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webflux-ui', version: '2.0.2'

2. 检查基础配置是否正确

  • 确认application.yml或application.properties中没有禁用springdoc的相关配置,默认是开启的,若有自定义配置需确保:
    springdoc.api-docs.enabled=true
    springdoc.swagger-ui.enabled=true
    
  • 确保你的控制器是WebFlux兼容的:比如返回Mono<T>或Flux<T>类型的响应,而非同步返回值。

3. 排查自动配置生效情况

启动应用时添加--debug参数,查看Spring Boot的自动配置报告,确认SpringDocWebFluxUiAutoConfiguration已经生效,没有被其他配置排除。如果该配置未生效,检查是否有自定义的@Configuration类覆盖了WebFlux的默认配置。

4. 验证访问路径

WebFlux环境下,swagger-ui的默认访问路径是/swagger-ui.html,同时可以访问/v3/api-docs查看接口文档的JSON数据:

  • 如果/v3/api-docs能正常返回数据,但/swagger-ui.html无法访问,可能是静态资源映射的问题,可尝试手动配置静态资源路径;
  • 如果两者都无法访问,需检查应用启动日志,查看是否有springdoc相关的报错信息。

内容的提问来源于stack exchange,提问作者Mohammad Mahdi Tilab

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 00:25:21