org.springframework.aop.target
abstract public class: AbstractPrototypeBasedTargetSource [javadoc |
source]
java.lang.Object
org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
org.springframework.aop.target.AbstractPrototypeBasedTargetSource
All Implemented Interfaces:
TargetSource, BeanFactoryAware, Serializable
Direct Known Subclasses:
CommonsPoolTargetSource, PrototypeTargetSource, AbstractPoolingTargetSource, ThreadLocalTargetSource
Base class for dynamic TargetSources that can 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 .
| Methods from org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource: |
|---|
|
copyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, releaseTarget, setBeanFactory, setTargetBeanName, setTargetClass, toString, writeReplace |
| Method from org.springframework.aop.target.AbstractPrototypeBasedTargetSource Detail: |
protected void destroyPrototypeInstance(Object target) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
}
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
}
else if (target instanceof DisposableBean) {
try {
((DisposableBean) target).destroy();
}
catch (Throwable ex) {
this.logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
}
}
}
Subclasses should call this method to destroy an obsolete prototype instance. |
protected Object newPrototypeInstance() throws BeansException {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Creating new instance of bean '" + getTargetBeanName() + "'");
}
return getBeanFactory().getBean(getTargetBeanName());
}
Subclasses should call this method to create a new prototype instance. |
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
super.setBeanFactory(beanFactory);
// Check whether the target bean is defined as prototype.
if (!beanFactory.isPrototype(getTargetBeanName())) {
throw new BeanDefinitionStoreException(
"Cannot use prototype-based TargetSource against non-prototype bean with name '" +
getTargetBeanName() + "': instances would not be independent");
}
}
|