【问题标题】:How to pass some parameter from before method to after in aspectj如何在aspectj中将一些参数从之前的方法传递到之后
【发布时间】:2018-06-17 12:29:11
【问题描述】:

下面是我的 aspectJ 类的代码

public aspect TestAspect {
String str;
long time;
pointcut callLoggingAspect():call(* com.dilip.bdp..*.*(..));
before() : callLoggingAspect() {
    str = thisJoinPoint.getSignature().toShortString();
    time = System.nanoTime();
}
after() : callLoggingAspect() {
    System.out.println(thisJoinPoint.getSignature().toShortString()+":Before="+str);
    System.out.println("Time taken by method "+thisJoinPoint.getSignature().toShortString()+" to execute ="+(System.nanoTime()-time));
}

}

我需要的是在 before() 中捕获一些东西,并在 after() 中使用该值用于相同的方法。 我正在设置一些值的当前代码是类级变量,在多线程环境中不起作用。 请建议我如何实现它

【问题讨论】:

    标签: java aop aspectj spring-aop


    【解决方案1】:

    非常简单:改用around() 建议。这里不需要任何高级技巧。

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 2017-10-17
      • 2015-05-01
      • 2017-04-28
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 2019-05-25
      • 2016-05-20
      相关资源
      最近更新 更多