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

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");

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

总结:

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

猜你喜欢

转载自www.cnblogs.com/dgwblog/p/11964069.html