Create pointcut based on annotation parameters
I am trying to create a pointcut based on the annotaion parameter
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface MyAnnotation {
Class<? extends ABC> style() default A.class;
}
And the pointcut I'm using at the moment:
@Pointcut("execution(@com.something.MyAnnotation * *(..))")
public void dummyMethod() {
}
@Around("method()")
public Object actualFunc(ProceedingJoinPoint joinPoint) throws Throwable {
//stuff
}
But this, unfortunately, is activated in all values โโof the style.
+3
source to share
1 answer
Obviously you could check the advice if the recommended method has the annotation value you're looking for, but it's not ideal (it's a runtime check). In your case, you can simply use the syntax:
@Pointcut("execution(@com.something.MyAnnotation(style=B.class) * *(..))")
Here's some information on the meaning of annotation matching: https://eclipse.org/aspectj/doc/released/README-160.html
+1
source to share