首页 > 编程语言 > 详细

Spring Boot 静态资源能加载css 不能加载js

时间:2019-11-30 22:30:47      阅读:74      评论:0      收藏:0      [点我收藏+]

Spring Boot 配置拦截器的时候默认 是放行 静态资源 , 也就是说不需要进行配置

 

registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/resources")
                .addResourceLocations("classpath:/static")
                .addResourceLocations("classpath:/templates")
                .addResourceLocations("classpath:/public");

 

但是 我发现一个问题 ,同一个目录结构能加载css img 但是不能加载 js 你说这个就奇葩了,

技术分享图片

 

        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/resources")
                .addResourceLocations("classpath:/static/") # 这里加个反斜杠
                .addResourceLocations("classpath:/templates")
                .addResourceLocations("classpath:/public");

 

我有单独在拦截器排除了 静态资源 ,发现还是不行, 那肯定资源没有加载进来,  后来 多加了一个反斜杠解决

 

总结:

我们处理静态资源的时候, 如果是多层目录 一定要 多加一个反斜杠

 

 

Spring Boot 静态资源能加载css 不能加载js

原文:https://www.cnblogs.com/dgwblog/p/11964069.html

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