Eclipse中的AspectJ LTW-切入点不适用于静态方法 [英] AspectJ LTW in eclipse - Pointcut does not work with static method

查看:144
本文介绍了Eclipse中的AspectJ LTW-切入点不适用于静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆