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

Springdoc中Swagger UI默认路径及访问失败问题咨询

正确访问路径(针对springdoc-openapi-ui 1.2.32版本)

你的springdoc版本属于旧版分支,对应的访问路径和高版本存在差异:

  • Swagger UI页面:http://localhost:8080/swagger-ui.html
  • OpenAPI 2.0文档(JSON格式):http://localhost:8080/v2/api-docs

你尝试的路径无效的原因

  1. localhost:8080/v3/apidocs:该路径是springdoc 1.3.x及以上版本(支持OpenAPI 3)的文档路径,1.2.x版本不兼容此路径
  2. localhost:8080/swagger-ui/:无后缀的路径是1.3.x+版本的UI访问方式,1.2.x仍需使用.html后缀的路径

额外排查点(若正确路径仍无法访问)

  • 若项目配置了上下文路径(server.servlet.context-path),需要在URL前添加该前缀,例如:http://localhost:8080/your-context-path/swagger-ui.html
  • 若启用了Spring Security,需放行Swagger相关资源,在Security配置中添加如下规则:
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/v2/api-docs", "/webjars/**")
            .permitAll()
            .anyRequest().authenticated();
    }
    
  • 检查项目启动日志,确认springdoc相关组件是否成功加载,无报错信息

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 01:05:10