为什么 JoinPoint 或 ProceedingJoinPoint 的对象可以调用方法?
How come JoinPoint or ProceedingJoinPoint's objects can call a method?
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 which is an implementation of ProceedingJoinPoint 的实例。
来自source code :
public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, JoinPoint.StaticPart {..}
为了回答您的问题,是的,Spring 框架有接口的实现。
您可以调试 Spring AOP 程序以观察运行时发生的情况。
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 which is an implementation of ProceedingJoinPoint 的实例。
来自source code :
public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, JoinPoint.StaticPart {..}
为了回答您的问题,是的,Spring 框架有接口的实现。
您可以调试 Spring AOP 程序以观察运行时发生的情况。