我在网上看到不是介绍但是,我尝试的时候,一直无法加载静态资源
后来我发现我使用的是springboot 1.5.7.RELEASE版本 ,应该这样
@Configuration
public class AppConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HttpInterceptor()).
addPathPatterns("/**").excludePathPatterns("/users/device/**","/users/user/**","/static/**");
super.addInterceptors(registry);
}
}
但是我在错误的使用extends WebMvcConfigurationSupport 的方式,虽然没有报错,而且也成功实现对非静态资源的拦截和不拦截,但是用这个方式即使excludePathPatterns了"/static/**",也还是屏蔽了静态资源,但是在springboot2.x这样用没有问题,所以如果用的是1.5.7版本,拦截器就用上面的方法。
@Configuration
public class AppConfigurer implements WebMvcConfiguter{
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new Interceptor()).addPathPatterns("/users/device/*").excludePathPatterns("/static/**");
registry.addInterceptor(new Interceptor()).addPathPatterns("/users/user/*").excludePathPatterns("/static/**");
registry.addInterceptor(new HttpInterceptor()).
addPathPatterns("/**").excludePathPatterns("/users/device/**","/users/user/**","/static/**");
}
}