Class AbstractBeanFactoryBasedTargetSourceCreator
java.lang.Object
org.springframework.aop.framework.autoproxy.target.AbstractBeanFactoryBasedTargetSourceCreator
- All Implemented Interfaces:
TargetSourceCreator,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.DisposableBean
- Direct Known Subclasses:
LazyInitTargetSourceCreator,QuickTargetSourceCreator
public abstract class AbstractBeanFactoryBasedTargetSourceCreator
extends Object
implements TargetSourceCreator, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean
Convenient superclass for
TargetSourceCreator
implementations that require creating multiple instances of a prototype bean.
Uses an internal BeanFactory to manage the target instances, copying the original bean definition to this internal factory. This is necessary because the original BeanFactory will just contain the proxy instance created through auto-proxying.
Requires running in an
AbstractBeanFactory.
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
-
AbstractBeanFactoryBasedTargetSourceAbstractBeanFactory
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.beans.factory.support.DefaultListableBeanFactorybuildInternalBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory containingFactory) Build an internal BeanFactory for resolving target beans.protected abstract AbstractBeanFactoryBasedTargetSourcecreateBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource if they wish to create a custom TargetSource for this bean, ornullif they are not interested it in, in which case no special target source will be created.voiddestroy()Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.protected final org.springframework.beans.factory.BeanFactoryReturn the BeanFactory that this TargetSourceCreators runs in.protected org.springframework.beans.factory.support.DefaultListableBeanFactorygetInternalBeanFactoryForBean(String beanName) Return the internal BeanFactory to be used for the specified bean.final TargetSourcegetTargetSource(Class<?> beanClass, String beanName) Create a special TargetSource for the given bean, if any.protected booleanReturn whether this TargetSourceCreator is prototype-based.final voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
AbstractBeanFactoryBasedTargetSourceCreator
public AbstractBeanFactoryBasedTargetSourceCreator()
-
-
Method Details
-
setBeanFactory
public final void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) - Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware
-
getBeanFactory
@Nullable protected final org.springframework.beans.factory.BeanFactory getBeanFactory()Return the BeanFactory that this TargetSourceCreators runs in. -
getTargetSource
Description copied from interface:TargetSourceCreatorCreate a special TargetSource for the given bean, if any.- Specified by:
getTargetSourcein interfaceTargetSourceCreator- Parameters:
beanClass- the class of the bean to create a TargetSource forbeanName- the name of the bean- Returns:
- a special TargetSource or
nullif this TargetSourceCreator isn't interested in the particular bean
-
getInternalBeanFactoryForBean
protected org.springframework.beans.factory.support.DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName) Return the internal BeanFactory to be used for the specified bean.- Parameters:
beanName- the name of the target bean- Returns:
- the internal BeanFactory to be used
-
buildInternalBeanFactory
protected org.springframework.beans.factory.support.DefaultListableBeanFactory buildInternalBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory containingFactory) Build an internal BeanFactory for resolving target beans.- Parameters:
containingFactory- the containing BeanFactory that originally defines the beans- Returns:
- an independent internal BeanFactory to hold copies of some target beans
-
destroy
public void destroy()Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- See Also:
-
isPrototypeBased
protected boolean isPrototypeBased()Return whether this TargetSourceCreator is prototype-based. The scope of the target bean definition will be set accordingly.Default is "true".
- See Also:
-
BeanDefinition.isSingleton()
-
createBeanFactoryBasedTargetSource
@Nullable protected abstract AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource if they wish to create a custom TargetSource for this bean, ornullif they are not interested it in, in which case no special target source will be created. Subclasses should not callsetTargetBeanNameorsetBeanFactoryon the AbstractPrototypeBasedTargetSource: This class' implementation ofgetTargetSource()will do that.- Parameters:
beanClass- the class of the bean to create a TargetSource forbeanName- the name of the bean- Returns:
- the AbstractPrototypeBasedTargetSource, or
nullif we don't match this
-