点击登录,精彩内容等着你

静态资源配置(spring.resources.static-locations)-2.7.4过期

全栈侠客

2022-10-07
springboot项目中,可以设置任意目录为静态资源访问路径,除了默认的/static/目录以外,可以根据实际情况配置相关路径为静态资源路径

springboot 2.5.3版本,配置静态资源路径的方法:
配置文件properties文件中,可以使用:spring.resources.static-locations来进行配置
但截止今天2022-10-07的最新springboot 2.7.4版本中,该配置已经失效

1.失效配置代码

  1. //1.上传图片文件的服务器路径
  2. leanboot.prop.upload-path=D:/filespath/leanboot/
  3. //2.springboot 2.5.3 版本是正常有效的,高版本2.5.5后就失效了
  4. spring.mvc.static-path-pattern=/**
  5. spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,\
  6. classpath:/static/,classpath:/public/,classpath:/pages/,file:${leanboot.prop.upload-path}

解析说明:

  • 多个路径使用,隔开
  • /static/虽然是默认为静态资源路径,单通过此种方式配置,需要重新加上该路径
  • classpath:代表是编译根路径
  • file:代表文件访问路径,后面的${leanboot.prop.upload-path}为配置的上传路径

2.新版本路径配置方法

  1. //.springboot 2.5.5 后版本的正常配置方法
  2. spring.mvc.static-path-pattern=/**
  3. spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,\
  4. classpath:/static/,classpath:/public/,classpath:/pages/,file:${leanboot.prop.upload-path}
阅读 1948     最后编辑 2022-10-07 22:11
文章补充
评论(0) 发表新评论
  • ...暂无评论...

我是有底线的 评论与点赞5分钟更新一次
回复评论
取消关闭

请先登录