Java Aspect returned value to be used in the method

谁说胖子不能爱 提交于 2019-12-02 13:15:21

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/37278282/java-aspect-returned-value-to-be-used-in-the-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!