spring-framework / org.springframework.aop.framework

Package org.springframework.aop.framework

Types

AbstractAdvisingBeanPostProcessor

abstract class AbstractAdvisingBeanPostProcessor : ProxyProcessorSupport, BeanPostProcessor

Base class for BeanPostProcessor implementations that apply a Spring AOP Advisor to specific beans.

AbstractSingletonProxyFactoryBean

abstract class AbstractSingletonProxyFactoryBean : ProxyConfig, FactoryBean<Any>, BeanClassLoaderAware, InitializingBean

Convenient superclass for FactoryBean types that produce singleton-scoped proxy objects.

Manages pre- and post-interceptors (references, rather than interceptor names, as in ProxyFactoryBean) and provides consistent interface management.

AopContext

abstract class AopContext

Class containing static methods used to obtain information about the current AOP invocation.

The currentProxy() method is usable if the AOP framework is configured to expose the current proxy (not the default). It returns the AOP proxy in use. Target objects or advice can use this to make advised calls, in the same way as getEJBObject() can be used in EJBs. They can also use it to find advice configuration.

Spring's AOP framework does not expose proxies by default, as there is a performance cost in doing so.

The functionality in this class might be used by a target object that needed access to resources on the invocation. However, this approach should not be used when there is a reasonable alternative, as it makes application code dependent on usage under AOP and the Spring AOP framework in particular.

DefaultAdvisorChainFactory

open class DefaultAdvisorChainFactory : AdvisorChainFactory, Serializable

A simple but definitive way of working out an advice chain for a Method, given an Advised object. Always rebuilds each advice chain; caching can be provided by subclasses.

DefaultAopProxyFactory

open class DefaultAopProxyFactory : AopProxyFactory, Serializable

Default AopProxyFactory implementation, creating either a CGLIB proxy or a JDK dynamic proxy.

Creates a CGLIB proxy if one the following is true for a given AdvisedSupport instance:

  • the optimize flag is set
  • the proxyTargetClass flag is set
  • no proxy interfaces have been specified

In general, specify proxyTargetClass to enforce a CGLIB proxy, or specify one or more interfaces to use a JDK dynamic proxy.

ProxyFactoryBean

open class ProxyFactoryBean : ProxyCreatorSupport, FactoryBean<Any>, BeanClassLoaderAware, BeanFactoryAware

org.springframework.beans.factory.FactoryBean implementation that builds an AOP proxy based on beans in Spring org.springframework.beans.factory.BeanFactory.

org.aopalliance.intercept.MethodInterceptor and org.springframework.aop.Advisor are identified by a list of bean names in the current bean factory, specified through the "interceptorNames" property. The last entry in the list can be the name of a target bean or a org.springframework.aop.TargetSource; however, it is normally preferable to use the "targetName"/"target"/"targetSource" properties instead.

Global interceptors and advisors can be added at the factory level. The specified ones are expanded in an interceptor list where an "xxx*" entry is included in the list, matching the given prefix with the bean names (e.g. "global*" would match both "globalBean1" and "globalBean2", "*" all defined interceptors). The matching interceptors get applied according to their returned order value, if they implement the org.springframework.core.Ordered interface.

Creates a JDK proxy when proxy interfaces are given, and a CGLIB proxy for the actual target class if not. Note that the latter will only work if the target class does not have final methods, as a dynamic subclass will be created at runtime.

It's possible to cast a proxy obtained from this factory to Advised, or to obtain the ProxyFactoryBean reference and programmatically manipulate it. This won't work for existing prototype references, which are independent. However, it will work for prototypes subsequently obtained from the factory. Changes to interception will work immediately on singletons (including existing references). However, to change interfaces or target it's necessary to obtain a new instance from the factory. This means that singleton instances obtained from the factory do not have the same object identity. However, they do have the same interceptors and target, and changing any reference will change all objects.

ReflectiveMethodInvocation

open class ReflectiveMethodInvocation : ProxyMethodInvocation, Cloneable

Spring's implementation of the AOP Alliance org.aopalliance.intercept.MethodInvocation interface, implementing the extended org.springframework.aop.ProxyMethodInvocation interface.

Invokes the target object using reflection. Subclasses can override the #invokeJoinpoint() method to change this behavior, so this is also a useful base class for more specialized MethodInvocation implementations.

It is possible to clone an invocation, to invoke #proceed() repeatedly (once per clone), using the #invocableClone() method. It is also possible to attach custom attributes to the invocation, using the #setUserAttribute / #getUserAttribute methods.

NOTE: This class is considered internal and should not be directly accessed. The sole reason for it being public is compatibility with existing framework integrations (e.g. Pitchfork). For any other purposes, use the ProxyMethodInvocation interface instead.