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

Spring Boot 3.0+Springdoc OpenAPI配置自定义上下文路径及Swagger UI

解决Spring Boot 3 + Springdoc OpenAPI路径配置问题

1. 配置应用全局上下文路径

直接在application.properties(或application.yml)里设置应用的默认上下文:

server.servlet.context-path=/myapp

2. 修正Springdoc路径配置

你之前的配置重复添加了/myapp前缀,会导致访问路径变成/myapp/myapp/xxx,属于无效配置。调整为以下内容:

# OpenAPI JSON文档访问路径:/myapp/api-docs
springdoc.api-docs.path=/api-docs
# Swagger UI访问路径:/myapp/swagger-ui.html
springdoc.swagger-ui.path=/swagger-ui.html
# 自定义YAML文档需带上上下文前缀,确保资源能被正确访问
springdoc.swagger-ui.urls.url=/myapp/test-service.yaml

配置验证

启动应用后,通过以下地址确认是否生效:

  • Swagger UI:http://localhost:你的端口/myapp/swagger-ui.html
  • OpenAPI JSON文档:http://localhost:你的端口/myapp/api-docs

内容的提问来源于stack exchange,提问作者Prabagaran Sellamuthu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 10:47:31