1

I have an @After java aspect that runs certain logic. I need it to return a result (an object) that can be used in the methods intercepted by the aspect's pointcut. Is it possible?

Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
Shai Givati
  • 1,106
  • 1
  • 10
  • 24

1 Answers1

3

What you need is @Around which allows you to return whatever you want to the advised object:

@Around("com.xyz.myapp.UserService.createUser()")
public Object userCreationAdvice(ProceedingJoinPoint pjp) throws Throwable {
    //Do something if needed before method execution
    Object retVal = pjp.proceed();
    //Do something if needed after method execution
    return retVal;
}
codependent
  • 23,193
  • 31
  • 166
  • 308