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

springdoc配置Swagger UI后重定向异常及No API definition问题排查

问题排查与修复方案

1. 安全配置路径错误

你的WebSecurity配置中,antMatchers("myservice/v3/api-docs/**")缺少开头的斜杠/,导致无法匹配到正确的API文档路径,Swagger UI请求API定义时会被拦截,进而显示"No API definition provided"。同时多余的/swagger-ui/index.html匹配规则可以移除,因为你的UI路径已被/myservice/swagger-ui/**覆盖。修改后的安全配置如下:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring()
        .antMatchers(HttpMethod.OPTIONS, "/**")
        .antMatchers("/myservice/swagger-ui/**")
        .antMatchers("/myservice/v3/api-docs/**");
}

2. 缺少Swagger UI的API文档路径指定

当前springdoc配置未明确Swagger UI要加载的API文档地址,需要在springdoc.swagger-ui节点下添加url属性,指向你的API文档路径。修改后的配置文件如下:

springdoc:
  swagger-ui:
    config-url: /myservice/v3/api-docs/swagger-config
    path: /myservice/swagger-ui/index.html
    disable-swagger-default-url: true
    url: /myservice/v3/api-docs # 新增配置,指定API文档路径
  api-docs:
    path: /myservice/v3/api-docs

3. 可选:关闭默认验证服务请求(若仍有问题)

如果修改后仍出现加载异常,可以添加validatorUrl: none关闭Swagger UI的默认远程验证服务请求,避免因网络或服务不可用导致的错误:

springdoc:
  swagger-ui:
    # 其他已有配置...
    validatorUrl: none

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 02:54:22