拦截器不拦截静态资源
拦截器代码
项目目录
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {
@Bean
public HandlerInterceptor getMyInterceptor() {
return new WeChatLoginInterceptor();
}
@Bean
public HandlerInterceptor getLoginOutInterceptor() {
return new WeChatLoginInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(getMyInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/static/image/**");
super.addInterceptors(registry);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("/","classpath:/");
}
}
注意 addInterceptors 方法里的 .excludePathPatterns("/static/image/**");
这里让拦截器不拦截 static/image
application.properties里什么都不用加
访问静态图片
localhost:8080/static/image/Aadd.png