今天遇到個坑就是后台轉發前台靜態文件時候前台css js找不到文件 全部爆紅 后來查找路徑也沒錯 。最終使用spring內部配置解決

@Configuration @EnableWebMvc public class MyWebMvcConfigurerConfig extends WebMvcConfigurerAdapter { @Resource private MyInterceptor myInterceptor; // @Override // public void addCorsMappings(CorsRegistry registry) { // super.addCorsMappings(registry); // registry.addMapping("/**") // .allowedOrigins("*") // .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") // .allowCredentials(true) // .allowedHeaders("*") // .maxAge(3600); // // } @Override public void addInterceptors(InterceptorRegistry registry) { //全部攔截 // registry.addInterceptor(myInterceptor).addPathPatterns("/**"); registry.addInterceptor(myInterceptor).excludePathPatterns("/**"); super.addInterceptors(registry); } //fixme:配置靜態資源訪問路徑 @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("/","classpath:/"); } }
