我有两个方面,每个方面修改方法参数.当两个方面都应用于同一个方法时,我希望将方面的执行链接起来,并且我希望第一个方面中修改的参数可用于第二个方面.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");
}
}
Run Code Online (Sandbox Code Playgroud)
方法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);
}
}
Run Code Online (Sandbox Code Playgroud)
和...
@Aspect
public class DoubleMooImpl {
@Pointcut("execution(@Moo * *(..))") …Run Code Online (Sandbox Code Playgroud)