默认Springboot将从如下位置按如下优先级(从高到低)加载jar包对应前端静态资源:
1.jar包同级static目录
2.jar包同级public目录
3.jar包同级resource目录
4.jar包/META-INF/resources
在调试模式下,Springboot将从class目录中按如下优先级(从高到低)加载对应前端静态资源
1.class目录下static目录
2.class目录下public目录
3.class目录下resource目录
4.class目录下/META-INF/resources
通过设置spring.resources.static-locations自定义Spring boot加载前端静态资源路径
spring.resources.static-locations: file:D:/public/
亦可以指定先后顺序:
spring.resources.static-locations=classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resource
如果指定了拦截器,该属性有可能失效
需要在拦截器ResourceHandlerRegistry中通过addLocations()指定对应路径。
如果指定@EnableWebMvc注解也会导致spring.resources.static-locations失效。如果使用@EnableWebMvc,会自动覆盖原有静态文件目录为src/main/webapp,如果要指定原静态文件目录,需重写addResourceHandlers方法
Original: https://www.cnblogs.com/lykbk/p/dfgfgfggfgfg43543543534543545.html
Author: 微笑点燃希望
Title: Spring boot项目设置加载静态资源的路径(spring.resources.static-locations)
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/540559/
转载文章受原作者版权保护。转载请注明原作者出处!