In my case, I am using the following advice
:
@Around(value = "@annotation(MyAnnotation) && args(MyArgs)")
and it works fine once the MyAnnotation is added to the method and MyArgs
will also retrieved.
@MyAnnotation(type = MyType.CREATE)
public void add(MyArgs) {
...
}
But in this post, it says:
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.
To my understanding, it seems right once the join point
reached and the condition is met, the advice should run (then my advice above will run twice - the call and the exeuction). And I should use the following advice to avoid it.
@Around(value = "@annotation(MyAnnotation) && execution(* *(..)) && args(MyArgs)")
But I debugged my code, it only runs once without adding execution(* *(..))
.
Is this right? Or it's not the way in which advice
runs?
Updated 2018-04-16
@Nandor is right, I was using Spring AOP instead of AspectJ. I started a maven demo clearly demonstating his point. Thank you, Nandor.