SpringBoot2.0以下,访问静态资源是默认放行的,2.0静态资源一并拦截。
需要加入"/static/", "/public/"
/**
* 拦截器配置
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/", "/webjars/**", "/static/**", "/public/**");
}
并且还要添更改默认配置路径,将系统默认"classpath:/static/“改为”/static/**"
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/public/**").addResourceLocations("classpath:/public/");
}
但这个产生一个问题,2.0以下前端thymeleaf可以@{/images/1.png}直接访问static里的images
<img th:src="@{/images/1.png}"