问题: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/");
}
}
版权声明:本文为博主作者:慢半拍的学长原创文章,版权归属原作者,如果侵权,请联系我们删除!
原文链接:https://blog.csdn.net/htx845928748/article/details/129686343