spring aop分析(三)

四、方法调用

    在JdkDynamicAopProxy类的invoke()方法中创建了一个ReflectiveMethodInvocation类,该方法将执行拦截器链和最终的方法调用:

public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Cloneable {

	public Object proceed() throws Throwable {
		// 若拦截器执行完毕,则运行目标对象上的方法
		if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size()) {
			return invokeJoinpoint();
		}

		Object interceptorOrInterceptionAdvice =
		    this.interceptorsAndDynamicMethodMatchers.get(this.currentInterceptorIndex);
		if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher) {
			...
                       // 计算动态interceptor是否执行
		}
		else {
			// 调用拦截器
			return ((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(nextInvocation());
		}
	}

	private ReflectiveMethodInvocation nextInvocation() throws CloneNotSupportedException {
		ReflectiveMethodInvocation invocation = (ReflectiveMethodInvocation) clone();
		invocation.currentInterceptorIndex = this.currentInterceptorIndex + 1;
		invocation.parent = this;
		return invocation;
	}

  ...
}

    invokeJoinpoint()方法将最终调用被代理的方法:

	protected Object invokeJoinpoint() throws Throwable {
		return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);
	}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值