
spring.mvc.static
1 spring.mvc.static-path-pattern
spring.mvc.static-path-pattern=/static/**只有静态资源的访问路径为/static/**时,才会处理请求。比如访问localhost:8080/static/a.css,处理方式是据模式匹配后的文件名查找本地文件。按spring.resources.static-locations指定查找的本地文件的位置。
2 spring.resources.static-locationsspring.resources.static-locations自定义Springboot前端静态资源的位置。默认Springboot将从如下位置,按优先级查找静态资源:
spring.resources.static-locations = classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources 3 配置file路径 # 反斜线,windows目录分隔符,前一个\\是转义字符,后一个\\是目录分隔符。 spring.resources.static-locations=file:\\\\d:\\\\dist\\\\ # 或spring.resources.static-locations=file:///d:/dist/ 4 WebMvcConfigurer配置代替 @Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry .addResourceHandler("/static/**") .addResourceLocations("/file:\\\\d:\\\\dist\\\\/") .setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()); } }参考:www.jianshu/p/21a7c7ccdec0.
👁️ 阅读量:0
© 版权声明:本文《spring.mvc.static》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686614389a305816.html。