List of usage examples for org.springframework.core.annotation AnnotatedElementUtils isAnnotated
public static boolean isAnnotated(AnnotatedElement element, String annotationName)
From source file:org.springframework.boot.test.context.SpringBootTestContextBootstrapper.java
private boolean containsNonTestComponent(Class<?>[] classes) { for (Class<?> candidate : classes) { if (!AnnotatedElementUtils.isAnnotated(candidate, TestConfiguration.class)) { return true; }/*w w w .j av a2 s . c o m*/ } return false; }
From source file:org.springframework.cloud.stream.reactive.StreamEmitterAnnotationBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { Class<?> targetClass = AopUtils.getTargetClass(bean); ReflectionUtils.doWithMethods(targetClass, method -> { if (AnnotatedElementUtils.isAnnotated(method, StreamEmitter.class)) { mappedStreamEmitterMethods.add(bean, method); }//from w w w . ja v a2s. c o m }, ReflectionUtils.USER_DECLARED_METHODS); return bean; }
From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java
@Override public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) { if (this.beanAnnotationAware() && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) { try {/*www. ja v a2 s .c om*/ resolveTargetBeanFromMethodWithBeanAnnotation(method); } catch (NoSuchBeanDefinitionException e) { if (this.logger.isDebugEnabled()) { this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation."); } return null; } } List<Advice> adviceChain = extractAdviceChain(beanName, annotations); MessageHandler handler = createHandler(bean, method, annotations); if (!CollectionUtils.isEmpty(adviceChain) && handler instanceof AbstractReplyProducingMessageHandler) { ((AbstractReplyProducingMessageHandler) handler).setAdviceChain(adviceChain); } if (handler instanceof Orderable) { Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class); if (orderAnnotation != null) { ((Orderable) handler).setOrder(orderAnnotation.value()); } } if (handler instanceof AbstractMessageProducingHandler || handler instanceof AbstractMessageRouter) { String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class); if (sendTimeout != null) { Long value = Long.valueOf(this.beanFactory.resolveEmbeddedValue(sendTimeout)); if (handler instanceof AbstractMessageProducingHandler) { ((AbstractMessageProducingHandler) handler).setSendTimeout(value); } else { ((AbstractMessageRouter) handler).setSendTimeout(value); } } } boolean handlerExists = false; if (this.beanAnnotationAware() && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) { Object handlerBean = this.resolveTargetBeanFromMethodWithBeanAnnotation(method); handlerExists = handlerBean != null && handler == handlerBean; } if (!handlerExists) { String handlerBeanName = generateHandlerBeanName(beanName, method); this.beanFactory.registerSingleton(handlerBeanName, handler); handler = (MessageHandler) this.beanFactory.initializeBean(handler, handlerBeanName); } if (AnnotatedElementUtils.isAnnotated(method, IdempotentReceiver.class.getName()) && !AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) { String[] interceptors = AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value(); for (String interceptor : interceptors) { DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor(); advisor.setAdviceBeanName(interceptor); NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); pointcut.setMappedName("handleMessage"); advisor.setPointcut(pointcut); advisor.setBeanFactory(this.beanFactory); if (handler instanceof Advised) { ((Advised) handler).addAdvisor(advisor); } else { ProxyFactory proxyFactory = new ProxyFactory(handler); proxyFactory.addAdvisor(advisor); handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader()); } } } if (!CollectionUtils.isEmpty(adviceChain)) { for (Advice advice : adviceChain) { if (advice instanceof HandleMessageAdvice) { NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(advice); handlerAdvice.addMethodName("handleMessage"); if (handler instanceof Advised) { ((Advised) handler).addAdvisor(handlerAdvice); } else { ProxyFactory proxyFactory = new ProxyFactory(handler); proxyFactory.addAdvisor(handlerAdvice); handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader()); } } } } AbstractEndpoint endpoint = createEndpoint(handler, method, annotations); if (endpoint != null) { return endpoint; } return handler; }
From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java
@Override public boolean shouldCreateEndpoint(Method method, List<Annotation> annotations) { String inputChannel = MessagingAnnotationUtils.resolveAttribute(annotations, getInputChannelAttribute(), String.class); boolean createEndpoint = StringUtils.hasText(inputChannel); if (!createEndpoint && beanAnnotationAware()) { boolean isBean = AnnotatedElementUtils.isAnnotated(method, Bean.class.getName()); Assert.isTrue(!isBean, "A channel name in '" + getInputChannelAttribute() + "' is required when " + this.annotationType + " is used on '@Bean' methods."); }// w w w .ja v a 2s . co m return createEndpoint; }