Class AbstractBeanFactoryBasedTargetsource

java.lang.Object
org.springframework.aop.target.AbstractBeanFactoryBasedTargetsource
All Implemented Interfaces:
serializable, TargetClassAware, Targetsource, Aware, BeanFactoryAware
Direct Known subclasses:
AbstractPrototypeBasedTargetsource, LazyInitTargetsource, simpleBeanTargetsource

public abstract class AbstractBeanFactoryBasedTargetsource extends Object implements Targetsource, BeanFactoryAware, serializable
Base class for Targetsource implementations that are based on a spring BeanFactory, delegating to spring-managed bean instances.

subclasses can create prototype instances or lazily access a singleton target, for example. see LazyInitTargetsource and AbstractPrototypeBasedTargetsource's subclasses for concrete strategies.

BeanFactory-based Targetsources are serializable. This involves disconnecting the current target and turning into a singletonTargetsource.

since:
1.1.4
Author:
Juergen Hoeller, Rod Johnson
see Also:
  • Field Details

    • logger

      protected final transient org.apache.commons.logging.Log logger
      Logger available to subclasses.
    • targetBeanName

      protected @Nullable string targetBeanName
      Name of the target bean we will create on each invocation.
  • Constructor Details

    • AbstractBeanFactoryBasedTargetsource

      public AbstractBeanFactoryBasedTargetsource()
  • Method Details

    • setTargetBeanName

      public void setTargetBeanName(string targetBeanName)
      set the name of the target bean in the factory.

      The target bean should not be a singleton, else the same instance will always be obtained from the factory, resulting in the same behavior as provided by singletonTargetsource.

      Parameters:
      targetBeanName - name of the target bean in the BeanFactory that owns this interceptor
      see Also:
    • getTargetBeanName

      public string getTargetBeanName()
      Return the name of the target bean in the factory.
    • setTargetClass

      public&nbsp;void&nbsp;setTargetClass(Class<?>&nbsp;targetClass)
      specify the target class explicitly, to avoid any kind of access to the target bean (for example, to avoid initialization of a FactoryBean instance).

      Default is to detect the type automatically, through a getType call on the BeanFactory (or even a full getBean call as fallback).

    • setBeanFactory

      public&nbsp;void&nbsp;setBeanFactory(BeanFactory&nbsp;beanFactory)
      set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.
      specified by:
      setBeanFactory&nbsp;in interface&nbsp;BeanFactoryAware
      Parameters:
      beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
      see Also:
    • getBeanFactory

      public&nbsp;BeanFactory&nbsp;getBeanFactory()
      Return the owning BeanFactory.
    • getTargetClass

      public&nbsp;@Nullable Class<?>&nbsp;getTargetClass()
      Description copied from interface:&nbsp;Targetsource
      Return the type of targets returned by this Targetsource.

      Can return null, although certain usages of a Targetsource might just work with a predetermined target class.

      specified by:
      getTargetClass&nbsp;in interface&nbsp;TargetClassAware
      specified by:
      getTargetClass&nbsp;in interface&nbsp;Targetsource
      Returns:
      the type of targets returned by this Targetsource
    • copyFrom

      protected&nbsp;void&nbsp;copyFrom(AbstractBeanFactoryBasedTargetsource&nbsp;other)
      Copy configuration from the other AbstractBeanFactoryBasedTargetsource object. subclasses should override this if they wish to expose it.
      Parameters:
      other - object to copy configuration from
    • equals

      public&nbsp;boolean&nbsp;equals(@Nullable Object&nbsp;other)
      Overrides:
      equals&nbsp;in class&nbsp;Object
    • hashCode

      public&nbsp;int&nbsp;hashCode()
      Overrides:
      hashCode&nbsp;in class&nbsp;Object
    • tostring

      public&nbsp;string&nbsp;tostring()
      Overrides:
      tostring&nbsp;in class&nbsp;Object