【问题标题】:How to get the caller method information from Around advise如何从Around advisor获取调用者方法信息
【发布时间】:2011-04-12 05:32:34
【问题描述】:

ThisJoinPoint 只能获取当前方法信息,反正获取调用者方法信息?

【问题讨论】:

    标签: aspectj


    【解决方案1】:

    您可以尝试特殊变量thisEnclosingJoinPointStaticPart,它包含封闭JoinPoint 的静态部分。

    提到了here(示例)和here(文档)

    或者如果使用基于注解的 AspectJ,请将以下内容传递给通知方法的参数,例如:

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

    提到here

    【讨论】:

    • 如何从@AspectJ 语法中得到这个?
    • 将此传递给通知方法的参数:JoinPoint.EnclosingStaticPart thisEnclosingJoinPointStaticPart(取自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());
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      相关资源
      最近更新 更多