Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory findAnnotationOnBean

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory findAnnotationOnBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory findAnnotationOnBean.

Prototype

@Nullable
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
        throws NoSuchBeanDefinitionException;

Source Link

Document

Find an Annotation of annotationType on the specified bean, traversing its interfaces and super classes if no annotation can be found on the given class itself, as well as checking the bean's factory method (if any).

Usage

From source file:org.jdal.beans.ParentBeanFactoryPostProcessor.java

/**
 * {@inheritDoc}//from   w  w w. j a  va 2 s. c o m
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    String[] names = beanFactory.getBeanDefinitionNames();

    for (String beanName : names) {
        Parent parent = beanFactory.findAnnotationOnBean(beanName, Parent.class);

        if (parent != null) {
            BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
            bd.setParentName(parent.value());
        }
    }
}

From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java

/**
 * Finds the beans to expose and puts them in the {@link #serviceBeanNames}
 * map.//from www . ja v  a2s  .  c  o m
 * <p>
 * Searches parent factories as well.
 */
private void findServiceBeanDefinitions(ConfigurableListableBeanFactory beanFactory) {
    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        JsonRpcService jsonRpcPath = beanFactory.findAnnotationOnBean(beanName, JsonRpcService.class);
        if (jsonRpcPath != null) {
            String pathValue = jsonRpcPath.value();
            LOG.fine(format("Found JSON-RPC path '%s' for bean [%s].", pathValue, beanName));
            if (serviceBeanNames.containsKey(pathValue)) {
                String otherBeanName = serviceBeanNames.get(pathValue);
                LOG.warning(format("Duplicate JSON-RPC path specification: found %s on both [%s] and [%s].",
                        pathValue, beanName, otherBeanName));
            }
            serviceBeanNames.put(pathValue, beanName);
        }
    }
    BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory();
    if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) {
        findServiceBeanDefinitions((ConfigurableListableBeanFactory) parentBeanFactory);
    }
}