0

この状況ではなく、なぜアドバイス@Afterが適用されるのか理解できません。@AfterThrowing

    @Pointcut("execution(* componentB.Bye.run())")
    public void newThread(){
    }

    @After("newThread()")
    public void cokolwiek2(JoinPoint joinPoint){
        report(joinPoint);
    }

    @AfterThrowing(pointcut="newThread()",throwing="e")
public void itsAFoo(JoinPoint joinPoint, RemoteException e) {
        logger.error(joinPoint.getSignature().toLongString() + " exception here!");
}

私は例外がスローされると確信しています:

public String greeting(String c) throws RemoteException,
        InterruptedException {
    throw new RemoteException();
    //return "Good morning!";
}

しかし、ログはありませんexception here!

4

1 に答える 1

2

ポイントカットexecution(* componentB.Bye.run())はメソッドをカバーしていませんpublic String greeting(String c)

@Afterとの違いは@AfterThrowing@AfterThrowing例外が発生した場合にのみ呼び出さ@Afterれ、例外がスローされた場合、またはメソッドが正常に返された場合に呼び出されることです。したがって、例外があり、両方のアドバイスがある場合は、両方が実行されます。

于 2012-08-07T14:46:44.813 に答える