Eclipse中的AspectJ LTW-切入点不适用于静态方法 [英] AspectJ LTW in eclipse - Pointcut does not work with static method
问题描述
我有一个Aspect类,它定义了一个切入点表达式,如下所示
I have an Aspect class, which defines one point-cut expression as below
@Pointcut("execution(* com.vg.pw.tasks.shared.*.executeTasks(..))")
public void myTraceCall() {}
其中executeTasks()方法是静态的.如果方法是非静态的,则在每次调用executeTasks()
时都将执行方法主体.为什么我的切入点在静态方法上无效?
where the executeTasks() method is static. If the method is made to non-static, the method body is executed on every call of executeTasks()
. Why is my pointcut not effective on static methods?
我正在使用LTW,而不是spring.
I'm using LTW and not spring.
推荐答案
我刚刚试用了切入点表达式,它可以按需在静态方法和非静态方法上工作.我使用了AspectJ weaver 1.8.7.尝试将-showWeaveInfo
和-verbose
添加到aop.xml中以获取有关LTW的调试信息.
I just tried out your pointcut expression and it works on both static and non-static methods just as it should. I used AspectJ weaver 1.8.7. Try adding -showWeaveInfo
and -verbose
to your aop.xml for debug info on LTW.
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver options="-showWeaveInfo -verbose">
<include within="q35218146..*" />
</weaver>
<aspects>
<aspect name="q35218146.Aspect35218146"/>
</aspects>
</aspectj>
应该在stderr上提供类似于以下内容的输出:
It should give you output on stderr similar to this:
[AppClassLoader@14dad5dc] weaveinfo Join point 'method-execution(void q35218146.
Test35218146.executeTasks())' in Type 'q35218146.Test35218146' (Test35218146.java:6)
advised by before advice from 'q35218146.Aspect35218146' (Aspect35218146.java)
这篇关于Eclipse中的AspectJ LTW-切入点不适用于静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!