springboot static resource access can be configured in two ways
1. Code Method
Code ways need to enable @EnableWebMvc notes, while achieving WebMvcConfigurer Interface
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/*").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/**").addResourceLocations("file:/Users/guoxiang/Documents/product-template/");
}
2. Profiles way
spring:
resources:
static-locations:
- classpath:/static/
- file:/Users/guoxiang/Documents/product-template/
Note that :
- If EnableWebMvc start, the configuration file is invalid, you can only choose one of two ways
- After the path configuration, must end with "/", otherwise configuration is invalid