Springboot 再模板引擎中引入Js等文件,出现服务器拒绝访问的错误,需要配置过滤器
静态资源访问配置
@Configuration @EnableWebMvc public class StaticResourceConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }
内置tomcat虚拟文件映射路径
@Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/image/**").addResourceLocations("file:C:/image/"); } }