I have multiple classes from different packages that extends a class Super. And i want to create an AOP pointcut around that match all the methods in all classes that extends Super. I have tried this:
@Around("within(com.mypackage.that.contains.super..*)")
public void aroundAllEndPoints(ProceedingJoinPoint joinPoint) throws Throwable {
LOGGER.info("before Proceed ");
joinPoint.proceed();
LOGGER.info("after Proceed");
}
But it doesn't work. Any Suggestions?
The pointcut should be:
within(com.mypackage.Super+)
where com.mypackage.Super
is the fully qualified base class name and +
means "all subclasses". This works for Spring AOP. In AspectJ this would match too many joinpoints, not just method executions. Here is another pointcut that works for both Spring AOP and AspectJ:
execution(* com.mypackage.Super+.*(..))
Quick update after a recent upvote, me noticing that I ought to have mentioned this before. If you want to retain the original pointcut and also favour separation of concerns, I recommend the more lengthy but somewhat more readable:
within(com.mypackage.Super+) && execution(* *(..))