SpringBoot默认的静态资源访问方案 两种方式自定义静态资源位置
一、SpringBoot默认的静态资源访问方案
# 我们在SpringBoot中找到WebMvcAutoConfiguration配置类
# 接下来找到addResourceHandlers方法
# .addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations()))
# 我们去找到String staticPathPattern = this.mvcProperties.getStaticPathPattern();
# 一直找下去找到private String staticPathPattern = "/**";
# 先不管这部分,我们再去找到addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations()))
# 通过this.resourceProperties.getStaticLocations()找到
public String[] getStaticLocations() {
return this.staticLocations;
}
# 通过return this.staticLocations; 最终找到
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/","classpath:/resources/", "classpath:/static/", "classpath:/public/" };
# 通过这段代码和创建文件夹的测试
# 得