spring boot 拦截器添加

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired private XxxInterceptor xxxInterceptor;//需要在该拦截器上添加@Configuration注解才能注入
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new YourInterceptor()).addPathPatterns("/xx/**")//要拦截的请求
.excludePathPatterns(
"/xxx/*");//不拦截的请求
registry.addInterceptor(xxxInterceptor).addPathPatterns("xxx/xx")//推荐
} }
posted @ 2016-05-25 13:56  until-u  阅读(2617)  评论(0编辑  收藏  举报