我在使用 spring 和使用 AspectJ 的 Load-Time-Weaving 时遇到了一些奇怪的问题。在我的一个 Apsect 中,我想对 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 一样编织?
克里斯