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

springdoc-openapi-ui加载报错,需手动输入API文档路径

解决springdoc-openapi 2.5.0 Swagger UI加载配置失败问题

问题分析

使用springdoc-openapi-starter-webmvc-ui:2.5.0时,访问https://example.com:8080/myapp/swagger-ui/index.html页面提示“Failed to load remote configuration”,浏览器Network面板显示首次加载时请求swagger-config返回404;手动在Explore栏输入/myapp/v3/api-docs后页面恢复正常,说明API文档本身可用,问题出在Swagger UI默认的配置加载路径逻辑上。

解决方案

通过调整springdoc配置,修正Swagger UI的配置加载路径,或直接指定默认API文档地址:

方案1:显式指定Swagger UI默认加载的API文档地址

取消注释springdoc.swagger-ui.url配置,简化冗余项,确保路径匹配:

springdoc.api-docs.path=/myapp/v3/api-docs
springdoc.swagger-ui.path=/myapp/swagger-ui.html
# 直接指定默认加载的API文档地址,跳过swagger-config请求流程
springdoc.swagger-ui.url=/myapp/v3/api-docs

方案2:基于应用上下文自动适配(推荐)

如果你的应用已通过server.servlet.context-path=/myapp配置了上下文路径,可使用更简洁的配置,让springdoc自动处理路径拼接:

server.servlet.context-path=/myapp
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.url=/myapp/v3/api-docs

配置无效原因说明

你之前配置的springdoc.swagger-ui.configUrl=/myapp/v3/api-docs/swagger-config,理论上是基于springdoc.api-docs.path拼接的swagger-config路径,但可能因多配置项冲突、swagger-config生成路径未正确匹配等原因导致404。直接指定swagger-ui.url可跳过swagger-config的请求环节,直接加载可用的API文档,更高效解决问题。

内容的提问来源于stack exchange,提问作者Scala Enthusiast

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 15:49:52