【问题标题】:AspectJ Advice Defined but not appliedAspectJ 建议已定义但未应用
【发布时间】:2020-07-12 17:28:29
【问题描述】:

所有,我试图找到解决方案,但不知何故它欺骗了我。我正在尝试使用 H2 驱动程序打印出一些痕迹。方面如下:

pointcut getMajorVersion_pointcut() :
    call(int org.h2.Driver.getMajorVersion());

before() : getMajorVersion_pointcut() {
    System.out.println("Before Advice:: driver executed");
}

这很完美,我得到了输出“Before Advice:: driver executed”。

但是,另一个建议是有问题:

pointcut accept_pointcut(String url) :
    call(boolean org.h2.Driver.acceptsURL(String)) && args(url);

before(String url) : accept_pointcut(url) {
    System.out.println(url);
}

Eclipse 正在标记“...中定义的建议尚未应用”

截图如下:

从左侧面板中可以看出,H2 驱动程序具有带有签名的方法。谁能指出我正确的方向。

【问题讨论】:

    标签: aop aspectj


    【解决方案1】:

    调用Driver.acceptsURL(String)的代码在哪里?它必须在您的编织(应用程序)代码中的某个位置。如果调用是从 H2 库中进行的,则不会被拦截,因为该代码超出了 AspectJ 的控制范围。如果你想改变这种情况,你需要

    • 要么将库放在 inpath 上并编织 H2 类,创建库的编织版本并在运行时使用它而不是原始版本,
    • 或使用加载时编织 (LTW) 并在类加载期间动态编织 H2 库。

    【讨论】:

    • 感谢您的指点,我在inpath inclusing上使用了第一种方法,它工作得很好。我会接受答案。
    猜你喜欢
    • 2014-12-10
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多