我想截取对某个对象的所有调用:org.springframework.data.redis.core.StringRedisTemplace
(例如save();
delete();
),但只有当我的公司中的许多软件包com.mycompany.*
直接进行调用时,才会在第三方库使用StringRedisTemplace
时或spring / data / redis本身。
有没有办法用AOP注释如@Pointcut
@Around
等来做到这一点。我的搜索/尝试都没有成功。
所以用一个词=>如何拦截/检测对某个类的所有实例的所有调用,只要这些实例在我的公司包中被实例化和使用。
好吧,你几乎是自己说的:
但只有当我的公司内部的许多包裹
com.mycompany.*
直接进行调用时
你需要的切入点类型确实命名为within
。在完整的AspectJ中有一个名为withincode
的相关名称,但基于代理的Spring AOP仅支持前者,而不支持后者。对于后者,您必须在Spring中通过LTW使用完整的AspectJ。所有内容都在Spring手册的AOP chapter中进行了解释。
你想要做的是这样的:
within(com.mycompany..*) && call(org.springframework.data.redis.core.StringRedisTemplate+.*(..))