swagger文档访问地址404

问题:swagger配置好以后,过滤器也设置了允许匿名访问。但是访问接口地址报404:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
swaggwer接口地址访问报错
一种可能的原因:未给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

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2024年4月1日
下一篇 2024年4月1日

相关推荐