org.springframework.aop.aspectj.annotation

## Class BeanFactoryAspectInstanceFactory

- java.lang.Object
- - org.springframework.aop.aspectj.annotation.BeanFactoryAspectInstanceFactory

- All Implemented Interfaces:
    MetadataAwareAspectInstanceFactory, AspectInstanceFactory, Ordered
  Direct Known Subclasses:
    PrototypeAspectInstanceFactory

      public class BeanFactoryAspectInstanceFactory
      extends Object
      implements MetadataAwareAspectInstanceFactory

  `AspectInstanceFactory` implementation backed by a Spring `BeanFactory`.

  Note that this may instantiate multiple times if using a prototype, which probably won't give the semantics you expect. Use a `LazySingletonAspectInstanceFactoryDecorator` to wrap this to ensure only one new aspect comes back.

  Since:
    2.0
  Author:
    Rod Johnson, Juergen Hoeller
  See Also:
    `BeanFactory`, `LazySingletonAspectInstanceFactoryDecorator`

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name)` Create a BeanFactoryAspectInstanceFactory.
    `BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class type)` Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should introspect to create AJType metadata.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ClassLoader` | `getAspectClassLoader()` Expose the aspect class loader that this factory uses.
    `Object` | `getAspectInstance()` Create an instance of this factory's aspect.
    `AspectMetadata` | `getAspectMetadata()` Return the AspectJ AspectMetadata for this factory's aspect.
    `int` | `getOrder()` Determine the order for this factory's target aspect, either an instance-specific order expressed through implementing the `Ordered` interface (only checked for singleton beans), or an order expressed through the `Order` annotation at the class level.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### BeanFactoryAspectInstanceFactory

          public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory,
                                          String name)

      Create a BeanFactoryAspectInstanceFactory. AspectJ will be called to introspect to create AJType metadata using the type returned for the given bean name from the BeanFactory.
      Parameters:
        `beanFactory` - BeanFactory to obtain instance(s) from
        `name` - name of the bean

    - #### BeanFactoryAspectInstanceFactory

          public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory,
                                          String name,
                                          Class type)

      Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should introspect to create AJType metadata. Use if the BeanFactory may consider the type to be a subclass (as when using CGLIB), and the information should relate to a superclass.
      Parameters:
        `beanFactory` - BeanFactory to obtain instance(s) from
        `name` - the name of the bean
        `type` - the type that should be introspected by AspectJ

  - ### Method Detail

    - #### getAspectInstance

          public Object getAspectInstance()

      Description copied from interface: `AspectInstanceFactory`
      Create an instance of this factory's aspect.
      Specified by:
        `getAspectInstance` in interface `AspectInstanceFactory`
      Returns:
        the aspect instance (never `null`)

    - #### getAspectClassLoader

          public ClassLoader getAspectClassLoader()

      Description copied from interface: `AspectInstanceFactory`
      Expose the aspect class loader that this factory uses.
      Specified by:
        `getAspectClassLoader` in interface `AspectInstanceFactory`
      Returns:
        the aspect class loader (never `null`)

    - #### getAspectMetadata

          public AspectMetadata getAspectMetadata()

      Description copied from interface: `MetadataAwareAspectInstanceFactory`
      Return the AspectJ AspectMetadata for this factory's aspect.
      Specified by:
        `getAspectMetadata` in interface `MetadataAwareAspectInstanceFactory`
      Returns:
        the aspect metadata

    - #### getOrder

          public int getOrder()

      Determine the order for this factory's target aspect, either an instance-specific order expressed through implementing the `Ordered` interface (only checked for singleton beans), or an order expressed through the `Order` annotation at the class level.
      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value
      See Also:
        `Ordered`, `Order`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`