public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFactoryBasedTargetSource
TargetSource
implementations
that create new prototype bean instances to support a pooling or
new-instance-per-invocation strategy.
Such TargetSources must run in a BeanFactory
, as it needs to
call the getBean
method to create a new prototype instance.
Therefore, this base class extends AbstractBeanFactoryBasedTargetSource
.
BeanFactory.getBean(java.lang.String)
,
PrototypeTargetSource
,
ThreadLocalTargetSource
,
CommonsPoolTargetSource
,
Serialized Formlogger
Constructor and Description |
---|
AbstractPrototypeBasedTargetSource() |
Modifier and Type | Method and Description |
---|---|
protected void |
destroyPrototypeInstance(Object target)
Subclasses should call this method to destroy an obsolete prototype instance.
|
protected Object |
newPrototypeInstance()
Subclasses should call this method to create a new prototype instance.
|
void |
setBeanFactory(BeanFactory beanFactory)
Set the owning BeanFactory.
|
protected Object |
writeReplace()
Replaces this object with a SingletonTargetSource on serialization.
|
copyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, releaseTarget, setTargetBeanName, setTargetClass, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getTarget
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
AbstractBeanFactoryBasedTargetSource
getBean
method on every invocation.setBeanFactory
in interface BeanFactoryAware
setBeanFactory
in class AbstractBeanFactoryBasedTargetSource
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeansException
- in case of initialization errorsBeanInitializationException
protected Object newPrototypeInstance() throws BeansException
BeansException
- if bean creation failedprotected void destroyPrototypeInstance(Object target)
target
- the bean instance to destroyprotected Object writeReplace() throws ObjectStreamException
writeReplace()
method must be visible to the class
being serialized.)
With this implementation of this method, there is no need to mark non-serializable fields in this class or subclasses as transient.
ObjectStreamException