美文网首页
springboot - 配置静态资源

springboot - 配置静态资源

作者: 尼尔君 | 来源:发表于2018-07-17 11:17 被阅读0次

配置静态目录,一共两个属性

配置请求规则

spring.mvc.static-path-pattern=/**

ex:

spring.mvc.static-path-pattern=/abc/**

也就是说 url请求地址为/abc/开头的 才会被处理

配置静态目录

默认情况下:

spring.resources.static-locations=classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources

我们可以根据需求来自己定义

spring.resources.static-locations=classpath:/static/img/,classpath:/static/css/
image.png

如果springboot是jar包运行的时候,我们需要把资源放到其他目录下。

所以我们可以这样:

web.upload-path=c:/jsr_img/
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,\
  classpath:/static/,classpath:/public/,file:${web.upload-path}  

相关文章

网友评论

      本文标题:springboot - 配置静态资源

      本文链接:https://www.haomeiwen.com/subject/rdewpftx.html