两个属性spring.mvc.static-path-pattern和spring.resources.static-locations
spring.mvc.static-path-pattern:/** (这是源码中的默认值)
//设置为/static/**的话 需要在url中请求资源时需要加上/static/才能正常访问,
//不设置也可以正常访问
源码如图:
spring.resources.static-locations= //(设置静态资源的目录,默认值见下图)
springboot会自动按照默认值的顺序优先级查找这几个目录下的静态资源
源码如图:
public static class Resources {
private static final String[]
CLASSPATH_RESOURCE_LOCATIONS =
new String[]{
"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"};
private String[] staticLocations;
pri