public abstract class AbstractBeanFactoryBasedTargetSourceCreator extends Object implements TargetSourceCreator, BeanFactoryAware, DisposableBean
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
.
AbstractBeanFactoryBasedTargetSource
,
AbstractBeanFactory
Constructor and Description |
---|
AbstractBeanFactoryBasedTargetSourceCreator() |
Modifier and Type | Method and Description |
---|---|
protected DefaultListableBeanFactory |
buildInternalBeanFactory(ConfigurableBeanFactory containingFactory)
Build an internal BeanFactory for resolving target beans.
|
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. |
void |
destroy()
Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.
|
protected BeanFactory |
getBeanFactory()
Return the BeanFactory that this TargetSourceCreators runs in.
|
protected DefaultListableBeanFactory |
getInternalBeanFactoryForBean(String beanName)
Return the internal BeanFactory to be used for the specified bean.
|
TargetSource |
getTargetSource(Class<?> beanClass,
String beanName)
Create a special TargetSource for the given bean, if any.
|
protected boolean |
isPrototypeBased()
Return whether this TargetSourceCreator is prototype-based.
|
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
|
protected final Log logger
public AbstractBeanFactoryBasedTargetSourceCreator()
public final void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
protected final BeanFactory getBeanFactory()
public final TargetSource getTargetSource(Class<?> beanClass, String beanName)
TargetSourceCreator
getTargetSource
in interface TargetSourceCreator
beanClass
- the class of the bean to create a TargetSource forbeanName
- the name of the beannull
if this TargetSourceCreator isn't
interested in the particular beanprotected DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName)
beanName
- the name of the target beanprotected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory)
containingFactory
- the containing BeanFactory that originally defines the beanspublic void destroy()
destroy
in interface DisposableBean
getInternalBeanFactoryForBean(java.lang.String)
protected boolean isPrototypeBased()
Default is "true".
BeanDefinition.isSingleton()
protected abstract AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName)
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.beanClass
- the class of the bean to create a TargetSource forbeanName
- the name of the beannull
if we don't match this