List of usage examples for org.springframework.web.method ControllerAdviceBean findAnnotatedBeans
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context)
From source file:co.paralleluniverse.springframework.web.servlet.mvc.method.annotation.FiberRequestMappingHandlerAdapter.java
private void initControllerAdviceCache() { if (getApplicationContext() == null) { return;//from w ww . ja va 2 s . c o m } if (logger.isDebugEnabled()) { logger.debug("Looking for controller advice: " + getApplicationContext()); } List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext()); Collections.sort(beans, new OrderComparator()); for (ControllerAdviceBean bean : beans) { Set<Method> attrMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(), MODEL_ATTRIBUTE_METHODS); if (!attrMethods.isEmpty()) { this.modelAttributeAdviceCache.put(bean, attrMethods); logger.info("Detected @ModelAttribute methods in " + bean); } Set<Method> binderMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(), INIT_BINDER_METHODS); if (!binderMethods.isEmpty()) { this.initBinderAdviceCache.put(bean, binderMethods); logger.info("Detected @InitBinder methods in " + bean); } } }
From source file:org.springframework.web.reactive.result.method.annotation.ControllerMethodResolver.java
private void initControllerAdviceCaches(@Nullable ApplicationContext applicationContext) { if (applicationContext == null) { return;//from ww w . j a v a2s .c om } if (logger.isInfoEnabled()) { logger.info("Looking for @ControllerAdvice: " + applicationContext); } List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(applicationContext); AnnotationAwareOrderComparator.sort(beans); for (ControllerAdviceBean bean : beans) { Class<?> beanType = bean.getBeanType(); if (beanType != null) { Set<Method> attrMethods = selectMethods(beanType, ATTRIBUTE_METHODS); if (!attrMethods.isEmpty()) { this.modelAttributeAdviceCache.put(bean, attrMethods); if (logger.isInfoEnabled()) { logger.info("Detected @ModelAttribute methods in " + bean); } } Set<Method> binderMethods = selectMethods(beanType, BINDER_METHODS); if (!binderMethods.isEmpty()) { this.initBinderAdviceCache.put(bean, binderMethods); if (logger.isInfoEnabled()) { logger.info("Detected @InitBinder methods in " + bean); } } ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(beanType); if (resolver.hasExceptionMappings()) { this.exceptionHandlerAdviceCache.put(bean, resolver); if (logger.isInfoEnabled()) { logger.info("Detected @ExceptionHandler methods in " + bean); } } } } }