Java Aspect returned value to be used in the method

前端 未结 1 1953

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

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 00:37

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

    0 讨论(0)
提交回复
热议问题