spring boot静态资源路径配置

  • 通过yml方式进行定义
    这里的需求是定义服务器加载的图片路径,配置项为
    resource.path.prefix: D:/share/data/space,正确配置如下:
spring:
  mvc:
    static-path-pattern: /**
  resources:
    static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${resource.path.prefix}
#The directory of adc resource located
resource.path.prefix: D:/share/data/space

这里遇到的问题是,是使用 STS,自动添加相应配置项,带有“-”,导致配置多个路径的时候,配置不生效

spring:
  mvc:
    static-path-pattern: /**
  resources:
    static-locations:
    - classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${adc.resource.path.prefix}
#The directory of adc resource located
adc.resource.path.prefix: D:/share/data/adcspace

但是单独配置,如下,是可以读取到图片的,还需要进一步了解机制

spring:
  mvc:
    static-path-pattern: /**
  resources:
    static-locations:
    - file:${adc.resource.path.prefix}
#The directory of adc resource located
adc.resource.path.prefix: D:/share/data/adcspace
发布了15 篇原创文章 · 获赞 4 · 访问量 3257

猜你喜欢

转载自blog.csdn.net/dongzhi1129/article/details/90142730