@AspectJ pointcut for all methods of a class with specific annotation

You should combine a type pointcut with a method pointcut. These pointcuts will do the work to find all public methods inside a class marked with an @Monitor annotation: @Pointcut(“within(@org.rejeev.Monitor *)”) public void beanAnnotatedWithMonitor() {} @Pointcut(“execution(public * *(..))”) public void publicMethod() {} @Pointcut(“publicMethod() && beanAnnotatedWithMonitor()”) public void publicMethodInsideAClassMarkedWithAtMonitor() {} Advice the last pointcut that combines … Read more

Spring AOP vs AspectJ

Spring-AOP Pros It is simpler to use than AspectJ, since you don’t have to use LTW (load-time weaving) or the AspectJ compiler. It uses the Proxy pattern and the Decorator pattern Spring-AOP Cons This is proxy-based AOP, so basically you can only use method-execution joinpoints. Aspects aren’t applied when calling another method within the same … Read more

Emulate annotation inheritance for interfaces and methods with AspectJ

The problem here is not AspectJ but the JVM. In Java, annotations on interfaces, methods or other annotations are never inherited by implementing classes, overriding methods or classes using annotated annotations. Annotation inheritance only works from classes to subclasses, but only if the annotation type used in the superclass bears the meta annotation @Inherited, see … Read more

Spring @Transaction method call by the method within the same class, does not work?

It’s a limitation of Spring AOP (dynamic objects and cglib). If you configure Spring to use AspectJ to handle the transactions, your code will work. The simple and probably best alternative is to refactor your code. For example one class that handles users and one that process each user. Then default transaction handling with Spring … Read more