我有兩個方面,每個方面都修改方法參數。當兩個方面都應用於相同的方法時,我期望執行方面被鏈接,並且我期望在第一方面修改的參數可以通過joinPoint.getArgs();
在第二方面提供。但是,看起來每個方面只能得到原始的論點;第二個方面從來沒有看到修改後的值。我做作的例子:在多個方面修改參數提供圍繞建議
測試類:
public class AspectTest extends TestCase {
@Moo
private void foo(String boo, String foo) {
System.out.println(boo + foo);
}
public void testAspect() {
foo("You should", " never see this");
}
}
的方法foo()是由兩方面的建議:
@Aspect
public class MooImpl {
@Pointcut("execution(@Moo * *(..))")
public void methodPointcut() {}
@Around("methodPointcut()")
public Object afterMethodInControllerClass(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("MooImpl is being called");
Object[] args = joinPoint.getArgs();
args[0] = "don't";
return joinPoint.proceed(args);
}
}
和...
@Aspect
public class DoubleMooImpl {
@Pointcut("execution(@Moo * *(..))")
public void methodPointcut() {}
@Around("methodPointcut()")
public Object afterMethodInControllerClass(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("DoubleMooImpl is being called");
Object[] args = joinPoint.getArgs();
args[1] = " run and hide";
return joinPoint.proceed(args);
}
}
我期望輸出爲:
MooImpl is being called
DoubleMooImpl is being called
don't run and hide
...但就是:
MooImpl is being called
DoubleMooImpl is being called
You should run and hide
我使用正確的方法通過各地的意見,修改參數?
請訂閱AspectJ用戶郵件列表並在那裏提出您的問題。你應該在那裏得到一個合格的答案。我也會對結果感興趣。 – kriegaex