我想使用 aspectj 来分析一个库。我的计划是用注释标记需要分析的方法:
@Profiled("logicalUnitOfWork")
然后有一个方面会在方法之前和之后触发,这些方法将使用logicalUnitOfWork
来突出显示已分析的内容。
所以,我的切入点看起来像这样。请注意,我在这里没有注释的论据;这是我不知道该怎么做的事情之一:
pointcut profiled() : execution(@Profiled * *());
before() : profiled () {
// : the profiled logical name is in this variable:
String logicalEventType;
Profiler.startEvent (logicalEventType);
}
after() returning : profiled() {
// : the profiled logical name is in this variable:
String logicalEventType;
Profiler.endEvent (logicalEventType);
}
被分析的方法将被定义如下:
@Profiled("someAction")
public void doAction (args...) {}
简而言之,我怎样才能将@Profiled
注释的值放入方面?我不需要根据值限制发生的分析,我只需要它对建议可见。另外,我是否需要将注释的保留设置为运行时才能正常工作,还是可以改为使用类级别的保留?