aspectj-weaver和spring-weaver之间的加载时间编织差异

时间:2011-06-22 08:33:05

标签: spring aspectj load-time-weaving

我使用AspectJ使用spring和Load-Time-Weaving有一些奇怪的问题。 在我的一个Apsects中,我想对类org.springframework.flex.security3.SpringSecurityLoginCommand的“doAuthentication”方法的调用做出反应。因此我创建了一个方法:

@Around("execution(* org.springframework.flex.security3.SpringSecurityLoginCommand.doAuthentication(..))")
public Object aroundDoAuthentication(ProceedingJoinPoint pjp) throws Throwable {
...

如果我使用aspectj-weaver代理,这个方面是正确编织的,但如果我使用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)) {
    ...

使用上面的代码,我设法正确地编织了每一个,但我对此并不满意,因为它对我来说似乎是个大黑客。

有谁能解释为什么使用Spring-Weaver我不能像使用aspectj-weaver那样编织?

克里斯

1 个答案:

答案 0 :(得分:0)

我不知道代码,但这个问题也是同样的问题。

Spring AOP基于默认代理。

这意味着只有来自bean外部的方法的调用才能通过代理进行。因此,只有此调用才能触发AOP建议。

相关问题