I want to execute a simple log on all methods of annotated class with a custom annotation. I've created the next annotation:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface FooAnnotation {}
And it's used on a random class:
@FooAnnotation
public class Bar{
...
}
Of course my start class has @EnableAspectJAutoProxy annotation
@EnableAspectJAutoProxy
@SpringBootApplication
public class FooApplication {
public static void main(String[] args) {
SpringApplication.run(FooApplication.class, args);
}
}
In the related AspectJ I need to define a @Pointcut to execute @After on all methods of all clases that are annotated with @FooAnnotation
I tried the next AspectJ and it doesn't work
@Slf4j
@Aspect
@Component
public class FooAspectJ{
@Pointcut("within(x.y.z.FooNotify)")
private void annotatedWithin() {}
@Pointcut("@within(x.y.z.FooNotify)")
private void annotatedAtWithin() {}
@Pointcut("@annotation(x.y.z.FooNotify)")
private void annotatedAtAnnotation() {}
@After("annotatedWithin() || annotatedAtWithin() || annotatedAtAnnotation()")
private void afterAnnotation(JoinPoint joinPoint){
log.info("Executed annotated {}", joinPoint.getSignature().getName());
}
}
I see similar post about this, like @AspectJ pointcut for all methods of a class with specific annotation and aspectj pointcut with annotation parameters, with the same result.