最近写项目本来写的好好的,突然static的静态页面访问不了了.

 SpringBoot放置在static下面的静态页面无法访问 随笔

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

于是我各种上网查资料,看大佬的解决方案,还是没有解决.

直到发现了这篇文章

https://blog.csdn.net/cmqwan/article/details/83934249  感谢大佬解决了我的问题

原因是我设置了自定义拦截器,导致静态资源无法获取.

解决方法也很简单:

public class WebMvcInterceptorConfig extends WebMvcConfigurationSupport {
 
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
String[] excludes = new String[] { "/static/**", "**.html", "/login.html" };
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/")
.addResourceLocations("classpath:/resources/").addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/public/");

super.addResourceHandlers(registry);
}
}
加上这个就完美解决了.
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄