Top Description Fields Constructors Methods
org.springframework.aop.framework.autoproxy.target

public abstract Class AbstractBeanFactoryBasedTargetSourceCreator

extends Object
implements TargetSourceCreator, BeanFactoryAware, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.aop.framework.autoproxy.TargetSourceCreator
Known Direct Subclasses
org.springframework.aop.framework.autoproxy.target.LazyInitTargetSourceCreator, org.springframework.aop.framework.autoproxy.target.QuickTargetSourceCreator
Imports
java.util.HashMap, .Map, org.apache.commons.logging.Log, .LogFactory, org.springframework.aop.TargetSource, org.springframework.aop.framework.AopInfrastructureBean, org.springframework.aop.framework.autoproxy.TargetSourceCreator, org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .DisposableBean, org.springframework.beans.factory.config.BeanDefinition, .ConfigurableBeanFactory, org.springframework.beans.factory.support.DefaultListableBeanFactory, .GenericBeanDefinition, org.springframework.lang.Nullable, org.springframework.util.Assert

Convenient superclass for org.springframework.aop.framework.autoproxy.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 org.springframework.beans.factory.support.AbstractBeanFactory.

Authors
Rod Johnson, Juergen Hoeller
See Also
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource, org.springframework.beans.factory.support.AbstractBeanFactory

Field Summary

Modifier and TypeField and Description
private ConfigurableBeanFactory
private final Map<String, DefaultListableBeanFactory>
internalBeanFactories

Internally used DefaultListableBeanFactory instances, keyed by bean name.

protected final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected DefaultListableBeanFactory

Returns:

an independent internal BeanFactory to hold copies of some target beans
buildInternalBeanFactory
(ConfigurableBeanFactory
the containing BeanFactory that originally defines the beans
containingFactory
)

Build an internal BeanFactory for resolving target beans.

protected abstract AbstractBeanFactoryBasedTargetSource

Returns:

the AbstractPrototypeBasedTargetSource, or null if we don't match this
createBeanFactoryBasedTargetSource
(Class<?>
the class of the bean to create a TargetSource for
beanClass
,
String
the name of the bean
beanName
)

Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource if they wish to create a custom TargetSource for this bean, or null if they are not interested it in, in which case no special target source will be created.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.

protected final BeanFactory
getBeanFactory()

Return the BeanFactory that this TargetSourceCreators runs in.

private ConfigurableBeanFactory
protected DefaultListableBeanFactory

Returns:

the internal BeanFactory to be used
getInternalBeanFactoryForBean
(String
the name of the target bean
beanName
)

Return the internal BeanFactory to be used for the specified bean.

public final TargetSource
getTargetSource(Class<?>
the class of the bean to create a TargetSource for
beanClass
,
String
the name of the bean
beanName
)

Implements org.springframework.aop.framework.autoproxy.TargetSourceCreator.getTargetSource.

Create a special TargetSource for the given bean, if any.

protected boolean
isPrototypeBased()

Return whether this TargetSourceCreator is prototype-based.

public final void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanFactoryback to summary
private ConfigurableBeanFactory beanFactory
Annotations
@Nullable
internalBeanFactoriesback to summary
private final Map<String, DefaultListableBeanFactory> internalBeanFactories

Internally used DefaultListableBeanFactory instances, keyed by bean name.

loggerback to summary
protected final Log logger

Constructor Detail

AbstractBeanFactoryBasedTargetSourceCreatorback to summary
public AbstractBeanFactoryBasedTargetSourceCreator()

Method Detail

buildInternalBeanFactoryback to summary
protected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory)

Build an internal BeanFactory for resolving target beans.

Parameters
containingFactory:ConfigurableBeanFactory

the containing BeanFactory that originally defines the beans

Returns:DefaultListableBeanFactory

an independent internal BeanFactory to hold copies of some target beans

createBeanFactoryBasedTargetSourceback to summary
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, or null if they are not interested it in, in which case no special target source will be created. Subclasses should not call setTargetBeanName or setBeanFactory on the AbstractPrototypeBasedTargetSource: This class' implementation of getTargetSource() will do that.

Parameters
beanClass:Class<?>

the class of the bean to create a TargetSource for

beanName:String

the name of the bean

Returns:AbstractBeanFactoryBasedTargetSource

the AbstractPrototypeBasedTargetSource, or null if we don't match this

Annotations
@Nullable
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.

Annotations
@Override
See Also
getInternalBeanFactoryForBean
getBeanFactoryback to summary
protected final BeanFactory getBeanFactory()

Return the BeanFactory that this TargetSourceCreators runs in.

Annotations
@Nullable
getConfigurableBeanFactoryback to summary
private ConfigurableBeanFactory getConfigurableBeanFactory()
getInternalBeanFactoryForBeanback to summary
protected DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName)

Return the internal BeanFactory to be used for the specified bean.

Parameters
beanName:String

the name of the target bean

Returns:DefaultListableBeanFactory

the internal BeanFactory to be used

getTargetSourceback to summary
public final TargetSource getTargetSource(Class<?> beanClass, String beanName)

Implements org.springframework.aop.framework.autoproxy.TargetSourceCreator.getTargetSource.

Doc from org.springframework.aop.framework.autoproxy.TargetSourceCreator.getTargetSource.

Create a special TargetSource for the given bean, if any.

Parameters
beanClass:Class<?>

the class of the bean to create a TargetSource for

beanName:String

the name of the bean

Returns:TargetSource

a special TargetSource or null if this TargetSourceCreator isn't interested in the particular bean

Annotations
@Override
@Nullable
isPrototypeBasedback to summary
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
org.springframework.beans.factory.config.BeanDefinition#isSingleton()
setBeanFactoryback to summary
public final void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override