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

如何禁用springdoc Swagger UI页面的默认/v3/api-docs定义?

禁用默认/v3/api-docs并设置自定义OpenAPI YAML为Swagger UI默认展示项

针对你使用的springdoc-openapi-ui:1.6.9,可以通过以下几步实现需求:

1. 关闭自动生成的默认/v3/api-docs端点

在application.properties或application.yml中添加配置,禁用SpringDoc自动生成的API文档端点:

application.properties:

springdoc.api-docs.enabled=false

application.yml:

springdoc:
  api-docs:
    enabled: false

2. 配置Swagger UI默认加载自定义YAML文件

同样在配置文件中指定Swagger UI默认访问的自定义文件路径:

application.properties:

springdoc.swagger-ui.url=/openapi-spec.yaml

application.yml:

springdoc:
  swagger-ui:
    url: /openapi-spec.yaml

3. 确保自定义YAML文件可被访问

将你的openapi-spec.yaml文件放到Spring Boot项目的src/main/resources/static或src/main/resources/public目录下,Spring Boot的静态资源映射会自动处理这个文件的访问请求。

完成配置后,启动项目访问Swagger UI(默认地址为/swagger-ui.html),会直接加载你自定义的OpenAPI规范;同时默认的/v3/api-docs端点被禁用,访问该地址会返回404。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 21:20:43