就我而言,我使用以下建议:
@Around(value = "@annotation(MyAnnotation) && args(MyArgs)")
一旦将MyAnnotation添加到方法并且MyArgs也将被检索,它就可以正常工作.
@MyAnnotation(type = MyType.CREATE)
public void add(MyArgs) {
...
}
但是在这个post中,它说:
The errors that can and will occur
Using only annotations creates another problem that we don’t need to think about while using patterns; It will make our advice run twice(or more), because the annotation pointcut don’t specify if it should be run during execution or initialization.
根据我的理解,似乎一旦达到连接点并满足条件,建议应该运行(然后我的建议将运行两次 – 调用和执行).我应该使用以下建议来避免它.
@Around(value = "@annotation(MyAnnotation) && execution(* *(..)) && args(MyArgs)")
但我调试了我的代码,它只运行一次而不添加执行(* *(..)).
这是正确的吗?或者不是建议运行的方式?
更新时间2018-04-16
@Nandor是对的,我使用的是Spring AOP而不是AspectJ.我开始了一个maven demo,清楚地表明了他的观点.谢谢,Nandor.