这个配置项是告诉springboot,应该以什么样的方式去寻找资源。默认配置为 /* 。换句话说,只有静态资源满足什么样的匹配条件,Spring Boot才会处理静态资源请求
# 默认值为 spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
根据前后关系确定优先级
可通过配置文件配置
mvc: static-path-pattern: /note/** resources: static-locations: classpath:/resources/note/
也可通过配置类注解
@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/note/"); } }
注意:
classpath 是指编译后classes 文件目录的相对路径
原文:https://www.cnblogs.com/cyh1282656849/p/12864280.html