AbstractBeanFactoryBasedTargetSource (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.aop.target

## 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:
    `BeanFactory.getBean(java.lang.String)`, `LazyInitTargetSource`, `PrototypeTargetSource`, `ThreadLocalTargetSource`, `CommonsPoolTargetSource`, Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger` Logger available to subclasses

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractBeanFactoryBasedTargetSource()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `copyFrom(AbstractBeanFactoryBasedTargetSource other)` Copy configuration from the other AbstractBeanFactoryBasedTargetSource object.
    `boolean` | `equals(Object other)`
    `BeanFactory` | `getBeanFactory()` Return the owning BeanFactory.
    `String` | `getTargetBeanName()` Return the name of the target bean in the factory.
    `Class<?>` | `getTargetClass()` Return the type of targets returned by this `TargetSource`.
    `int` | `hashCode()`
    `boolean` | `isStatic()` Will all calls to `TargetSource.getTarget()` return the same object?
    `void` | `releaseTarget(Object target)` Release the given target object obtained from the `TargetSource.getTarget()` method.
    `void` | `setBeanFactory(BeanFactory beanFactory)` Set the owning BeanFactory.
    `void` | `setTargetBeanName(String targetBeanName)` Set the name of the target bean in the factory.
    `void` | `setTargetClass(Class 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).
    `String` | `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`

- - ### Field Detail

    - #### logger

          protected final Log logger

      Logger available to subclasses

  - ### Constructor Detail

    - #### AbstractBeanFactoryBasedTargetSource

          public AbstractBeanFactoryBasedTargetSource()

  - ### Method Detail

    - #### 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:
        `SingletonTargetSource`

    - #### getTargetBeanName

          public String getTargetBeanName()

      Return the name of the target bean in the factory.

    - #### setTargetClass

          public void setTargetClass(Class 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 void setBeanFactory(BeanFactory 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` in interface `BeanFactoryAware`
      Parameters:
        `beanFactory` - owning BeanFactory (never `null`). The bean can immediately call methods on the factory.
      See Also:
        `BeanInitializationException`

    - #### getBeanFactory

          public BeanFactory getBeanFactory()

      Return the owning BeanFactory.

    - #### getTargetClass

          public Class<?> getTargetClass()

      Description copied from interface: `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` in interface `TargetClassAware`
      Specified by:
        `getTargetClass` in interface `TargetSource`
      Returns:
        the type of targets returned by this `TargetSource`

    - #### isStatic

          public boolean isStatic()

      Description copied from interface: `TargetSource`
      Will all calls to `TargetSource.getTarget()` return the same object?

      In that case, there will be no need to invoke `TargetSource.releaseTarget(Object)`, and the AOP framework can cache the return value of `TargetSource.getTarget()`.

      Specified by:
        `isStatic` in interface `TargetSource`
      Returns:
        `true` if the target is immutable
      See Also:
        `TargetSource.getTarget()`

    - #### releaseTarget

          public void releaseTarget(Object target)
                             throws Exception

      Description copied from interface: `TargetSource`
      Release the given target object obtained from the `TargetSource.getTarget()` method.
      Specified by:
        `releaseTarget` in interface `TargetSource`
      Parameters:
        `target` - object obtained from a call to `TargetSource.getTarget()`
      Throws:
        `Exception` - if the object can't be released

    - #### copyFrom

          protected void copyFrom(AbstractBeanFactoryBasedTargetSource 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 boolean equals(Object other)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`