Aspectj声明错误无法正常工作

时间:2013-07-03 12:36:02

标签: java aspectj pointcut

我正在尝试捕获方法签名更改并在发生时抛出错误。 但是声明错误没有按预期工作

@DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
public static final String errorMsg= "Signature error";

这始终与此方法的调用相匹配。

但如果我将此切入点移动到@Before,那么除非方法签名发生变化,否则它将不匹配。

任何想法为什么@DeclareError&之间的不同行为@Before关于切入点?

由于

1 个答案:

答案 0 :(得分:2)

奇怪 - 它适用于我的环境。 (带有AspectJ插件的Eclipse)

@Aspect
public class GetNameOverrider {

    @DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
    static final String errorMsg= "Signature error";
}
如果我这样做,

在编译时给出错误:

a.b.C c = new a.b.C();
c.method(new Integer(2)); <--- no Error
c.method(2); <--- no Error
c.method("test"); <--- Error

=============================

ErrorDescription    Resource    Path    Location    Type
"Signature error"   Main.java   /Stackoverflow/src/test line 12 AspectJ Problem