首页 > 编程语言 > 详细

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

时间:2019-04-21 16:19:35      阅读:807      评论:0      收藏:0      [点我收藏+]

最近写项目本来写的好好的,突然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);
}
}
加上这个就完美解决了.

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

原文:https://www.cnblogs.com/zbjj-itblog/p/10745536.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!