Package org.springframework.aop.target
Class AbstractPrototypeBasedTargetSource
java.lang.Object
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
org.springframework.aop.target.AbstractPrototypeBasedTargetSource
- All Implemented Interfaces:
Serializable
,TargetClassAware
,TargetSource
,Aware
,BeanFactoryAware
- Direct Known Subclasses:
AbstractPoolingTargetSource
,PrototypeTargetSource
,ThreadLocalTargetSource
public abstract class AbstractPrototypeBasedTargetSource
extends AbstractBeanFactoryBasedTargetSource
Base class for dynamic
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
.
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
destroyPrototypeInstance
(Object target) Subclasses should call this method to destroy an obsolete prototype instance.protected Object
Subclasses should call this method to create a new prototype instance.void
setBeanFactory
(BeanFactory beanFactory) Set the owning BeanFactory.protected Object
Replaces this object with a SingletonTargetSource on serialization.Methods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
copyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, setTargetBeanName, setTargetClass, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.aop.TargetSource
getTarget, isStatic, releaseTarget
-
Constructor Details
-
AbstractPrototypeBasedTargetSource
public AbstractPrototypeBasedTargetSource()
-
-
Method Details
-
setBeanFactory
Description copied from class:AbstractBeanFactoryBasedTargetSource
Set the owning BeanFactory. We need to save a reference so that we can use thegetBean
method on every invocation.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Overrides:
setBeanFactory
in classAbstractBeanFactoryBasedTargetSource
- Parameters:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- Throws:
BeansException
- in case of initialization errors- See Also:
-
newPrototypeInstance
Subclasses should call this method to create a new prototype instance.- Throws:
BeansException
- if bean creation failed
-
destroyPrototypeInstance
Subclasses should call this method to destroy an obsolete prototype instance.- Parameters:
target
- the bean instance to destroy
-
writeReplace
Replaces this object with a SingletonTargetSource on serialization. Protected as otherwise it won't be invoked for subclasses. (ThewriteReplace()
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.
- Throws:
ObjectStreamException
-