spring aop 之链式调用
关关雎鸠,在河之洲。窈窕淑女,君子好逑。 概述 AOP ( Aspect Orient Programming ),我们一般称为面向方面(切面)编程,作为面向对象的一种补充,用于处理系统中分布于各个模块的横切关注点,比如事务管理、日志、缓存等等。 Spring AOP 采用的是动态代理,在运行期间对业务方法进行增强,所以不会生成新类, Spring AOP 提供了对 JDK 动态代理的支持以及CGLib的支持。本章我们不关注 aop 代理类的实现,我简单实现一个指定次序的链式调用。 实现链式调用的 MethodInterceptor 定义拦截器链, MethodInvocation 递归进入下一个拦截器链中。类图如下: MethodInterceptor public interface MethodInterceptor { Object invoke(MethodInvocation invocation) throws Throwable; } MethodInvocation public interface MethodInvocation { Object proceed() throws Throwable; } AbstractAspectJAdvice 抽象类,实现 MethodInterceptor public abstract class