问题: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为例):

@Configuration

public class MvcConfig implements WebMvcConfigurer{

@Override

public 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/");

}

}

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: