Search in sources :

Example 1 with AbstractBeanFactoryBasedTargetSource

use of org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource in project spring-framework by spring-projects.

the class AbstractBeanFactoryBasedTargetSourceCreator method getTargetSource.

//---------------------------------------------------------------------
// Implementation of the TargetSourceCreator interface
//---------------------------------------------------------------------
@Override
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
    AbstractBeanFactoryBasedTargetSource targetSource = createBeanFactoryBasedTargetSource(beanClass, beanName);
    if (targetSource == null) {
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
    }
    DefaultListableBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);
    // We need to override just this bean definition, as it may reference other beans
    // and we're happy to take the parent's definition for those.
    // Always use prototype scope if demanded.
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
    GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
    if (isPrototypeBased()) {
        bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    }
    internalBeanFactory.registerBeanDefinition(beanName, bdCopy);
    // Complete configuring the PrototypeTargetSource.
    targetSource.setTargetBeanName(beanName);
    targetSource.setBeanFactory(internalBeanFactory);
    return targetSource;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AbstractBeanFactoryBasedTargetSource(org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

AbstractBeanFactoryBasedTargetSource (org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1