How to specify single pointcut for all classes that extend a specific class

做~自己de王妃 提交于 2021-01-27 07:04:56

问题


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?


回答1:


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+.*(..))


来源:https://stackoverflow.com/questions/38507316/how-to-specify-single-pointcut-for-all-classes-that-extend-a-specific-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!