MvcInterceptorManager extends WebInterceptorAdapter implements HandlerMappingListener, ApplicationContextAware, HandlerInterceptor, AsyncHandlerInterceptor { final protected Collection<AnnotationAttributes> findInterceptorAnnotationAttrsList(HandlerMethod hm){ Set<Interceptor> inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getMethod(), Interceptor.class); if(LangUtils.isEmpty(inters)){ inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getBeanType(), Interceptor.class); } if(LangUtils.isEmpty(inters)){ return Collections.emptyList(); } Collection<AnnotationAttributes> attrs = inters.stream() .map(inter->org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(null, inter)) .collect(Collectors.toSet()); boolean hasDisabledFlag = attrs.stream() .anyMatch(attr->asMvcInterceptorMeta(attr).getInterceptorType()==DisableMvcInterceptor.class); if(hasDisabledFlag){ return Collections.emptyList(); } return attrs; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex); @Override void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void setApplicationContext(ApplicationContext applicationContext); @Override void onHandlerMethodsInitialized(Map<RequestMappingInfo, HandlerMethod> handlerMethods); @Override int getOrder();  }
@Test public void testSubControllerUserAuthDisabled(){ SubControllerTest sub = new SubControllerTest(); Method userAuthDisabled = ReflectUtils.findMethod(SubControllerTest.class, "userAuthDisabled"); HandlerMethod hm = new HandlerMethod(sub, userAuthDisabled); List<AnnotationAttributes> attrs = new ArrayList<AnnotationAttributes>(mvcInterceptorMgr.findInterceptorAnnotationAttrsList(hm)); assertThat(attrs).isEmpty(); }
@Test public void testSub2ControllerUserAuthDisabled(){ Sub2ControllerTest sub = new Sub2ControllerTest(); Method userAuthDisabled = ReflectUtils.findMethod(Sub2ControllerTest.class, "userAuth"); HandlerMethod hm = new HandlerMethod(sub, userAuthDisabled); List<AnnotationAttributes> attrs = new ArrayList<AnnotationAttributes>(mvcInterceptorMgr.findInterceptorAnnotationAttrsList(hm)); assertThat(attrs).isEmpty(); }
@Test public void testSub3ControllerUserAuthDisabled(){ Sub3ControllerTest sub = new Sub3ControllerTest(); Method userAuthDisabled = ReflectUtils.findMethod(Sub3ControllerTest.class, "userAuth"); HandlerMethod hm = new HandlerMethod(sub, userAuthDisabled); List<AnnotationAttributes> attrs = new ArrayList<AnnotationAttributes>(mvcInterceptorMgr.findInterceptorAnnotationAttrsList(hm)); assertThat(attrs).isEmpty(); }