無法訪問static下的靜態資源
1.在application.yml中添加
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:./../images
2、配置webconfig
@EnableWebMvc @Configuration public class WebAppConfig implements WebMvcConfigurer { private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" }; @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new AppInterceptor()).addPathPatterns("/**").excludePathPatterns(""); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //配置server虛擬路徑,handler為頁面中訪問的目錄,locations為files相對應的本地路徑 registry.addResourceHandler("/static/**") .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS); } }
ok,可以訪問靜態資源了