List of usage examples for org.springframework.integration.config.annotation MethodAnnotationPostProcessor postProcess
Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations);
From source file:org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.java
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { Assert.notNull(this.beanFactory, "BeanFactory must not be null"); final Class<?> beanClass = this.getBeanClass(bean); if (!this.isStereotype(beanClass)) { // we only post-process stereotype components return bean; }//from w w w.j a v a 2 s.c o m ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() { @SuppressWarnings({ "unchecked", "rawtypes" }) public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { Annotation[] annotations = AnnotationUtils.getAnnotations(method); for (Annotation annotation : annotations) { MethodAnnotationPostProcessor postProcessor = postProcessors.get(annotation.annotationType()); if (postProcessor != null && shouldCreateEndpoint(annotation)) { Object result = postProcessor.postProcess(bean, beanName, method, annotation); if (result != null && result instanceof AbstractEndpoint) { String endpointBeanName = generateBeanName(beanName, method, annotation.annotationType()); if (result instanceof BeanNameAware) { ((BeanNameAware) result).setBeanName(endpointBeanName); } beanFactory.registerSingleton(endpointBeanName, result); if (result instanceof BeanFactoryAware) { ((BeanFactoryAware) result).setBeanFactory(beanFactory); } if (result instanceof InitializingBean) { try { ((InitializingBean) result).afterPropertiesSet(); } catch (Exception e) { throw new BeanInitializationException( "failed to initialize annotated component", e); } } if (result instanceof Lifecycle) { lifecycles.add((Lifecycle) result); if (result instanceof SmartLifecycle && ((SmartLifecycle) result).isAutoStartup()) { ((SmartLifecycle) result).start(); } } if (result instanceof ApplicationListener) { listeners.add((ApplicationListener) result); } } } } } }); return bean; }