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
