liveBook · Manning

ProceedingJoinPoint

As explained in Spring Start Here, Second Edition

ProceedingJoinPoint is a Spring AOP join-point object that exposes the intercepted invocation, including its method, arguments, target object, and continuation of execution.

A ProceedingJoinPoint represents the method intercepted by an aspect. In Spring AOP, it lets advice inspect details such as the method name, arguments, and target object, then decide how execution continues. section 6.2.2 section 6.2.1

An around advice can use it to control the intercepted call:

  • Call proceed() to run the intercepted method; without it, that method does not execute. section 6.2.1
  • Read the method name and arguments, pass replacement arguments to proceed(), or return a different value to the caller. section 6.2.2
  • proceed() can throw an exception from the intercepted method; advice can let it propagate or handle it. section 6.2.1

Changing a service call

A LoggingAspect can inspect a call to publishComment(), replace its Comment argument, and call proceed(newArguments). Even if the service returns SUCCESS, the advice can return FAILED to the caller. section 6.2.2

Listing 6.12 Obtaining the method name and parameters in the aspect logic
@Aspect
public class LoggingAspect {
 
  private Logger logger = Logger.getLogger(LoggingAspect.class.getName());
 
  @Around("execution(* com.example.services.*.*(..))")
  public Object log(ProceedingJoinPoint joinPoint) 
    throws Throwable {
 
    String methodName =                           #A
      joinPoint.getSignature().getName();         #A
    Object [] arguments = joinPoint.getArgs();    #A
 
    logger.info("Method " + methodName +   #B
        " with parameters " + Arrays.asList(arguments) +
        " will execute");
 
    Object returnedByMethod = joinPoint.proceed();    #C
 
    logger.info("Method executed and returned " + returnedByMethod);
 
    return returnedByMethod;  #D
  }
}

See the Java advice that reads the method name and arguments, proceeds with the call, and returns its result. section 6.2.2

How Spring Start Here, Second Edition covers it

How deep it goes
Details invocation inspection, continuation, argument replacement, return-value changes, and exception handling without exploring framework internals.
Examples
Uses a CommentService publishing example to log invocation details, replace a Comment argument, and return a different result.
What you can do after
Apply it via Spring AOP to inspect intercepted calls, control execution, and alter arguments or returned values.
How it connects
Connects to Spring AOP, aspects, around advice, pointcut expressions, and intercepted methods.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.