spring boot静态资源访问配置(访问项目文件夹外的文件)

很多类似的博文,但是实际配置后发现是有问题的。下面是完整的yml静态资源访问配置,在spring:下添加

mvc:
  static-path-pattern: /**                        #这个配置是默认配置
http:                                             #这里是访问项目外文件夹的关键
    multipart:
        locations: ${ruoyi.profile}
resources:
      static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, file:${spring.http.multipart.locations}        #需要把自定义的路径添加到static-locations后面,原本的静态访问路径也要加上不然原本的静态资源会访问不到。

(ruo.profile是自定义的路径,如:
ruoyi:
    profile:D:/profile
)访问时直接在访问路径上加上profile之后的路径,例如profile中有文件stuImg/test.jpg,则访问路径为localhost/stuImg/test.jpg

 

猜你喜欢

转载自blog.csdn.net/LeonShenZhi/article/details/83022136