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

访问Swagger UI遇“No static resource swagger-ui.html”错误求助

解决Swagger UI访问提示"No static resource swagger-ui.html"的问题

问题详情

  • 未配置自定义静态资源路径
  • Gradle依赖(代码不完整):springdoc.openapi.ui)
  • 访问URL:http://localhost:7666/al/swagger-ui.html
  • 错误信息:
    {
        "message": "No static resource swagger-ui.html.",
        "status": 500,
        "timestamp": "2023-12-08T18:50:22.998920556"
    }
    

排查与解决步骤

1. 修正Gradle依赖配置

你提供的依赖代码不完整,需补充完整坐标,且要匹配Spring Boot版本:

  • Spring Boot 3.x:
    // Groovy DSL
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
    
    // Kotlin DSL
    implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")
    
  • Spring Boot 2.x:
    // Groovy DSL
    implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'
    
    // Kotlin DSL
    implementation("org.springdoc:springdoc-openapi-ui:1.6.15")
    

版本不匹配会直接导致UI资源无法加载。

2. 对齐应用上下文与springdoc配置

访问URL里的/al说明应用配置了server.servlet.context-path=/al,需让springdoc的UI路径和上下文匹配:
在application.properties中添加:

springdoc.swagger-ui.path=/al/swagger-ui.html

也可以直接尝试访问版本适配的默认路径:http://localhost:7666/al/swagger-ui/index.html(部分springdoc版本的UI入口是index.html)。

3. 排除拦截器/过滤器对Swagger资源的拦截

如果项目有自定义拦截器或过滤器,必须排除Swagger相关静态资源路径,示例:

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(yourInterceptor)
            .excludePathPatterns("/swagger-ui/**", "/v3/api-docs/**");
}

4. 验证API文档核心接口

先访问http://localhost:7666/al/v3/api-docs(Spring Boot 3.x)或http://localhost:7666/al/v2/api-docs(Spring Boot 2.x),如果能返回JSON格式的API文档,说明核心配置正常,问题仅出在UI资源加载环节,可重点排查依赖完整性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 16:50:02