Spring Aspectj Around 建议不适用于接口实现

Spring Aspectj Around advice does not work with interface implementations

我有一个接口及其实现。

interface A{
    String methodA();
    String methodB();
}

public class Impl1 implements A{

    @Override
    public String methodA() {
        methodB();
        return "";
    }

    @Override
    public String methodB() {
        return "";
    }
}

public class Impl2 implements A{

    @Override
    public String methodA() {
        methodB();
        return "";
    }

    @Override
    public String methodB() {
        return null;
    }
}

当 A 接口的任何实现 && 执行 methodB() 时我想要拦截的内容。

@Around("within(com.bla.bla.A+) && execution(* methodB(..))")

但这没有用。当我删除执行部分时,它可以工作,但用于调用外部方法。任何想法将不胜感激。

注意:methodb不是在界面外直接触发的。它在接口实现中触发。

Spring AOP 适用于代理。从 methodA() 调用 methodB() 称为自调用。 Spring AOP 将无法建议从 methodA() 到 methodB() 的方法调用,因为它不会通过代理。

Spring 参考文档:Understanding AOP Proxies。通读以 开头的部分 这里要理解的关键是 main(..)

中的客户端代码