A before advice executes some extra code before the execution of the target method. In this recipe, we will log the arguments of the target method.
Here are the steps for logging the methods' arguments using a before advice:
In your aspect class, create an advice method annotated with
@Before
and takeJoinPoint
as an argument:@Before("execution(* com.spring_cookbook.controllers.*.*(..))") public void logArguments(JoinPoint joinPoint) { ... }
In that method, get the list of arguments of the target method:
Object[] arguments = joinPoint.getArgs();
Log the list of arguments preceded by the target method name:
String className = joinPoint.getSignature().getDeclaringTypeName(); String methodName = joinPoint.getSignature().getName(); System.out.println("-----" + className + "." + methodName + "() -----"); for (int i = 0; i < arguments.length...