我在使用 spring 和使用 AspectJ 的 Load-Time-Weaving 时遇到了一些奇怪的问题。 在我的一个 Apsect 中,我想对类 org.springframework.flex.security3.SpringSecurityLoginCommand 的“doAuthentication”方法的调用使用react。因此我创建了一个方法:
@Around("execution(* org.springframework.flex.security3.SpringSecurityLoginCommand.doAuthentication(..))")
public Object aroundDoAuthentication(ProceedingJoinPoint pjp) throws Throwable {
...
如果我使用 aspectj-weaver agent,这个方面是正确编织的,但是如果我使用 spring-weaver,这个方面会被忽略。不幸的是,如果我想要正确的 aspect-spring 集成,我必须使用 spring-weaver。我发现编织方面的唯一方法是围绕目标类的每个方法编织它并以编程方式过滤方面调用:
@Around("execution(* org.springframework.flex.security3.SpringSecurityLoginCommand.*(..))")
public Object aroundDoAuthentication(ProceedingJoinPoint pjp) throws Throwable {
final String methodName = pjp.getSignature().getName();
if("doAuthentication".equals(methodName)) {
...
使用上面的代码,我设法正确编织了所有东西,但我对此并不满意,因为这对我来说似乎是一个很大的 hack。
谁能解释一下为什么我使用 Spring-Weaver 无法编织出与 aspectj-weaver 相同的编织效果?
克里斯
最佳答案
我不知道代码,但这似乎是同一个老问题。
Spring AOP 是基于默认代理的。
这意味着只有来自 bean 外部的方法调用才会通过代理。因此只有这个调用可以触发 AOP 通知。
关于spring - aspectj-weaver 和 spring-weaver 之间的 Load-Time-Weaving 差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6437052/