java - PointCut to match method annotated with certain params to the annotation -
i have pointcut
@pointcut("execution(@com.foo.bar.aspect.annotation.myannotation* * (..))" + "&& @annotation(annot)") public void anyfoo(myannotation annot) { }
myannotation
looks this:
@target(elementtype.method) @retention(retentionpolicy.runtime) public @interface myannotation { boolean isfoo(); string name; }
let's annotate method annotation isfoo set true
@myannotation(isfoo = true, name = "hello") public void dothis() { system.out.println("hello, world"); }
how write pointcut matches method annotated myannotaion
, isfoo = true
?
i tried doesn't seem work
@pointcut("execution(@com.foo.bar.aspect.annotation.myannotation(isfoo = true, *) * * (..))" + "&& @annotation(annot)") public void anyfoo(myannotation annot) { }
you cannot write pointcut because aspectj not support it. need use like
@pointcut("execution(@com.foo.bar.aspect.annotation.myannotation* * (..))" + "&& @annotation(annot)") public void anyfoo(myannotation annot) { if (!annot.isfoo()) return; // continue here if annotation has right parameter value // ... }
Comments
Post a Comment