小工具知识网

当前位置: 首页 > 行业知识 > swagger文档访问地址404

行业知识

swagger文档访问地址404

2026-12-05 12:53:17 来源:互联网转载

问题:swagger配置好以后,过滤器也设置了允许匿名访问。但是访问接口地址报404:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

一种可能的原因:未给swagger配置资源路径,其他插件配置了资源路径,Spring MVC 找不到swagger需要的CSS、JS等资源。

解决方法:在WebMvcConfigurer中给swagger配置资源路径如下(以访问地址为swagger-ui.html为例):

@Configurationpublic class MvcConfig implements WebMvcConfigurer{ @Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry{ registry.addResourceHandler("/**")                .addResourceLocations("classpath:/static/");        registry.addResourceHandler("swagger-ui.html")                        .addResourceLocations("classpath:/META-INF/resources/");        registry.addResourceHandler("/webjars/**")                        .addResourceLocations("classpath:/META-INF/resources/webjars/");}}

上一篇:家用图形服务器怎么用的?

下一篇:阿里云服务器网络诊断