AopProxy是Spring Aop提供的代理类,简单来说通过其实现类可以获取到代理类。
AopProxy接口提供的方法如下:
public interface AopProxy {
/**
* Create a new proxy object.
* <p>Uses the AopProxy's default class loader (if necessary for proxy creation):
* usually, the thread context class loader.
* @return the new proxy object (never {@code null})
* @see Thread#getContextClassLoader()
*/
//获取一个代理对象
Object getProxy();
/**
* Create a new proxy object.
* <p>Uses the given class loader (if necessary for proxy creation).
* {@code null} will simply be passed down and thus lead to the low-level
* proxy facility's default, which is usually different from the default chosen
* by the AopProxy implementation's {@link #getProxy()} method.
* @param classLoader the class loader to create the proxy with
* (or {@code null} for the low-level proxy facility's default)
* @return the new proxy object (never {@code null})
*/
//根据类加载器获取代理对象
Object getProxy(ClassLoader classLoader);
}
AopProxy有两个实现类JdkDynamicAopProxy和CglibAopProxy,简单来说这两个代理类的功能就是生成目标代理类,其实现机制可以参考 Java--Proxy代理介绍及实现机制。