0

I want to execute some code for all methods annotated with @TestAnnotation or other annotations that are composed of it. I thought that using @Around("@annotation(TestAnnotation)") should do the trick however it only works for the exact match, but not for composed annotations like @ComposedTestAnnotation. Is this possible to make it work? I cannot find any examples of the described scenario.

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
public @interface TestAnnotation {
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@TestAnnotation
public @interface ComposedTestAnnotation {
}
@Aspect
@Service
@Slf4j
public class AspectService {

    @Around("@annotation(TestAnnotation)")
    public Object aroundTestAnnotation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("aroundTestAnnotation executed");
        return proceedingJoinPoint.proceed();
    }

}

Montes
  • 3
  • 2

0 Answers0