AOP,仅当直接从包 X 发出时如何拦截对给定 class 的调用
AOP, how to intercept calls to a given class only when made directly from a package X
我想拦截对某个对象的所有调用:org.springframework.data.redis.core.StringRedisTemplace
(例如 save();
delete();
)但只有当调用是直接从我的公司内部进行时许多包 com.mycompany.*
,而不是当 StringRedisTemplace
的实例被第三方库或 spring/data/redis 本身使用时。
有没有办法使用 @Pointcut
@Around
等 AOP 注释来做到这一点。我的 searches/attempts 没有成功。
所以一句话 => 如何 intercept/instrument 对某个 class 的所有实例的所有调用,只要这些实例在我的公司包中被实例化和使用。
好吧,你自己说的差不多了:
but only when the calls are made directly from within one of my corporation many packages com.mycompany.*
您需要的切入点类型确实命名为within
。 full AspectJ中有一个相关的叫withincode
,但是proxy-based Spring AOP只支持前者,不支持后者。对于后者,您必须在 Spring 内通过 LTW 使用完整的 AspectJ。 Spring 手册的 AOP chapter.
中解释了一切
你想要做的是这样的:
within(com.mycompany..*) && call(org.springframework.data.redis.core.StringRedisTemplate+.*(..))
我想拦截对某个对象的所有调用:org.springframework.data.redis.core.StringRedisTemplace
(例如 save();
delete();
)但只有当调用是直接从我的公司内部进行时许多包 com.mycompany.*
,而不是当 StringRedisTemplace
的实例被第三方库或 spring/data/redis 本身使用时。
有没有办法使用 @Pointcut
@Around
等 AOP 注释来做到这一点。我的 searches/attempts 没有成功。
所以一句话 => 如何 intercept/instrument 对某个 class 的所有实例的所有调用,只要这些实例在我的公司包中被实例化和使用。
好吧,你自己说的差不多了:
but only when the calls are made directly from within one of my corporation many packages
com.mycompany.*
您需要的切入点类型确实命名为within
。 full AspectJ中有一个相关的叫withincode
,但是proxy-based Spring AOP只支持前者,不支持后者。对于后者,您必须在 Spring 内通过 LTW 使用完整的 AspectJ。 Spring 手册的 AOP chapter.
你想要做的是这样的:
within(com.mycompany..*) && call(org.springframework.data.redis.core.StringRedisTemplate+.*(..))