问题: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/");
	}
}
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐