@FunctionalInterfaceSE public interface MethodInterceptor extends Interceptor
ユーザーは、invoke(MethodInvocation) メソッドを実装して、元の動作を変更する必要があります。例: 次のクラスは、トレースインターセプターを実装します(インターセプトされたメソッドのすべての呼び出しをトレースします)。
class TracingInterceptor implements MethodInterceptor {
Object invoke(MethodInvocation i) throws Throwable {
System.out.println("method "+i.getMethod()+" is called on "+
i.getThis()+" with args "+i.getArguments());
Object ret=i.proceed();
System.out.println("method "+i.getMethod()+" returns "+ret);
return ret;
}
}
| 修飾子と型 | メソッドと説明 |
|---|---|
ObjectSE | invoke(MethodInvocation invocation) このメソッドを実装して、呼び出しの前後に追加の処理を実行します。 |
@NullableSE ObjectSE invoke(@NonnullSE MethodInvocation invocation) throws ThrowableSE
Joinpoint.proceed() を呼び出すようにします。invocation - メソッド呼び出しジョインポイント Joinpoint.proceed() の呼び出しの結果。インターセプターによってインターセプトされる可能性があります ThrowableSE - インターセプターまたはターゲットオブジェクトが例外をスローする場合