Class 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.

Rod Johnson, Juergen Hoeller
See Also:
  • Constructor Details

    • AbstractPrototypeBasedTargetSource

      public AbstractPrototypeBasedTargetSource()
  • Method Details

    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      Description copied from class: AbstractBeanFactoryBasedTargetSource
      Set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.
      Specified by:
      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 errors
      See Also:
    • newPrototypeInstance

      protected Object newPrototypeInstance() throws BeansException
      Subclasses should call this method to create a new prototype instance.
      BeansException - if bean creation failed
    • destroyPrototypeInstance

      protected void destroyPrototypeInstance(Object target)
      Subclasses should call this method to destroy an obsolete prototype instance.
      target - the bean instance to destroy
    • writeReplace

      protected Object writeReplace() throws ObjectStreamException
      Replaces this object with a SingletonTargetSource on serialization. Protected as otherwise it won't be invoked for subclasses. (The 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.