How to get the caller method information from Around advise

六月ゝ 毕业季﹏ 提交于 2019-12-19 11:05:19

问题


ThisJoinPoint can only get the current method information, anyway to get the caller method information?


回答1:


You can try the special variable thisEnclosingJoinPointStaticPart which holds the static part of the enclosing JoinPoint.

Mentioned here (example) and here (docs)

Or if using annotation-based AspectJ, pass following to the advice method's parameters, e.g.:

@Before("call( /* your pointcut definition */ )")
public void myCall(JoinPoint.EnclosingStaticPart thisEnclosingJoinPointStaticPart)
{
     // ...
}

Mentioned here




回答2:


@Aspect
public class LoggingAspect {

    @Before(value = "execution(public * findAll())")
    public void beforeAdvice(JoinPoint pp){
        System.out.println("before advice called ....get calling method Signature"+pp.getSignature());
        System.out.println("before advice called ....get calling method name"+pp.getSignature().getName());
    }

}


来源:https://stackoverflow.com/questions/5630809/how-to-get-the-caller-method-information-from-around-advise

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