インターフェース MethodInterceptor

すべてのスーパーインターフェース:
Advice, Interceptor
すべての既知のサブインターフェース:
IntroductionInterceptor
すべての既知の実装クラス:
AbstractMonitoringInterceptor, AbstractRetryInterceptor, AbstractTraceInterceptor, AfterReturningAdviceInterceptor, AnnotationAsyncExecutionInterceptor, AspectJAfterAdvice, AspectJAfterThrowingAdvice, AspectJAroundAdvice, AsyncExecutionInterceptor, CacheInterceptor, ConcurrencyThrottleInterceptor, CustomizableTraceInterceptor, DebugInterceptor, DelegatePerTargetObjectIntroductionInterceptor, DelegatingIntroductionInterceptor, EventPublicationInterceptor, ExposeInvocationInterceptor, JCacheInterceptor, MBeanClientInterceptor, MBeanProxyFactoryBean, MethodBeforeAdviceInterceptor, MethodValidationInterceptor, PerformanceMonitorInterceptor, PersistenceExceptionTranslationInterceptor, SimpleRetryInterceptor, SimpleTraceInterceptor, ThrowsAdviceInterceptor, TransactionInterceptor
関数インターフェース:
これは関数インターフェースであるため、ラムダ式またはメソッド参照の割り当てターゲットとして使用できます。

@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;
  }
}
作成者:
Rod Johnson
  • メソッドのサマリー

    修飾子と型
    メソッド
    説明
    このメソッドを実装して、呼び出しの前後に追加の処理を実行します。
  • メソッドの詳細

    • invoke

      @Nullable ObjectSE invoke(MethodInvocation invocation) throws ThrowableSE
      このメソッドを実装して、呼び出しの前後に追加の処理を実行します。正しい実装としては、必ず Joinpoint.proceed() を呼び出すようにします。
      パラメーター:
      invocation - メソッド呼び出しジョインポイント
      戻り値:
      Joinpoint.proceed() の呼び出しの結果。インターセプターによってインターセプトされる可能性があります
      例外:
      ThrowableSE - インターセプターまたはターゲットオブジェクトが例外をスローする場合