I need to define a point cut which triggers the execution on all methods of a spring service annotated with a custom annotation. The annotation I would like to define the po
I had this exact need in an application. I found this answer, but wasn't satisfied this couldn't be done.
After a bit more searching, I found this cheat sheet for AspectJ/Spring pointcut expressions. The solution in the cheat sheet didn't work exactly as advertised, but I was able to make it work for what I needed.
@Pointcut("within(@(@Annotation *) *)")
public void classAnnotatedWithNestedAnnotationOneLevelDeep() { }
I combined this expression with a @within
expression for just the @Annotation
to get what I wanted to work.
For method execution:
@Pointcut("execution(@(@com.someorg.SomeAnnotation *) * *(..))")
public void methodAnnotatedWithNestedAnnotationOneLevelDeep() { }
I combined this expression with a @annotation
expression for just the @Annotation
to get what I wanted to work for methods.