1.静态资源文件路径
静态资源文件路径是指用户可以直接通过游览器访问到文件的存放位置。按照优先级有一下4个路径:
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
修改静态资源文件路径
YAML
spring: web: resources: static-locations: [file:D://upload/,classpath:/res/]
Properties
spring.web.resources.static-locations[0]=file:D://upload/ spring.web.resources.static-locations[1]=classpath:/res/ or spring.web.resources.static-locations=classpath:/res/
配置类class
@Configuration public class MyConfiguration implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**") .addResourceLocations("classpath:/res/") .addResourceLocations("file:D://upload/"); } }
2.默认配置文件的加载路径
classpath:表示资源文件加resources,/:表示项目根目录
加载顺序(优先级高的会覆盖优先级低的配置):/config > / > classpath/config > classpath/
标签:配置文件,路径,classpath,locations,默认,static,存放,resources From: https://www.cnblogs.com/ErenYeager/p/17008330.html