Search code examples
javaspring-mvcinterfaceaspectjspring-aop

How come JoinPoint or ProceedingJoinPoint's objects can call a method?


AspectJ's JoinPoint is an interface and ProceedingJoinPoint is also an interface that extends the Joinpoint.

However, when I use them in an aspect, I can use their instances and their methods directly.

@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;
}

How is this possible? Isn't the interface supposed to be implemented by some classes to be used?

Or Is it that the casting is done behind the scene in AspectJ?

Thank you,


Solution

  • At runtime the Spring framework provides the instance of MethodInvocationProceedingJoinPoint which is an implementation of ProceedingJoinPoint.

    From the source code :

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

    To answer your question , Yes , the Spring framework has an implementation for the interface.

    You may debug an Spring AOP program to observe what happens at runtime.