一、静态文件配置
1、默认情况下,静态文件映射模板为:/**,映射路径为:"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/",见 WebMvcProperties、ResourceProperties
2、默认配置可通过配置文件覆盖
spring.mvc.static-path-pattern=/abc/** spring.resources.static-locations=classpath:/static/
3、当使用@EnableWebMvc定义web配置时,默认配置或配置文件覆盖的配置失效,即使类无方法,此时须使用代码指定,
@Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); } }
4、在指定映射路径时,须以‘/’结尾,如"classpath:/static/",而非"classpath:/static",否则会失效