为什么 JoinPoint 或 ProceedingJoinPoint 的对象可以调用方法?



AspectJ的JoinPoint是一个接口,ProceedingJoinPoint也是一个扩展JoinPoint的接口。

然而,当我在一个方面使用它们时,我可以直接使用它们的实例和方法。

@Around("execution(* com.luv2code.aopdemo.dao.service.*.getFortune(..))")
public Object aroundGetFortune(
ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
String method = proceedingJoinPoint.getSignature().toShortString();
System.out.println("n=======> Executing @Around on method: " + method);
return null;
}

这怎么可能?接口不是应该由一些要使用的类来实现吗?

还是选角是在AspectJ的幕后完成的?

谢谢你,

在运行时,Spring框架提供MethodInvocationProceedingJoinPoint的实例,该实例是ProceedingJoinPoint的实现。

来自源代码:

public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, JoinPoint.StaticPart {..}

为了回答您的问题,是的,Spring框架有一个接口的实现。

您可以调试SpringAOP程序来观察运行时发生的情况。

最新更新