最近写项目本来写的好好的,突然static的静态页面访问不了了.
于是我各种上网查资料,看大佬的解决方案,还是没有解决.
直到发现了这篇文章
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);
}
}
加上这个就完美解决了.