クラス EventPublicationInterceptor

java.lang.ObjectSE
org.springframework.context.event.EventPublicationInterceptor
実装されているすべてのインターフェース:
Advice, Interceptor, MethodInterceptor, Aware, InitializingBean, ApplicationEventPublisherAware

public class EventPublicationInterceptor extends ObjectSE implements MethodInterceptor, ApplicationEventPublisherAware, InitializingBean
各 ApplicationEventPublisher で登録されたすべての ApplicationListeners に ApplicationEvent を発行する Interceptor は、各メソッド呼び出しが成功した後。

このインターセプターは、メソッド呼び出しが成功するたびに、"applicationEventClass" プロパティで設定されたカスタムイベントを発行できます。7.0.3 以降では、代わりに factory function を設定し、そこにプライマリ EventPublicationInterceptor.ApplicationEventFactory.onSuccess(MethodInvocation, Object) メソッドを実装できます。

デフォルト(7.0.3 時点)では、このインターセプターはメソッド呼び出しで発生したすべての例外に対して MethodFailureEvent を発行します。これは ApplicationListener<MethodFailureEvent> クラスまたは @EventListener(MethodFailureEvent.class) メソッドを介して簡単に追跡できます。失敗イベントは、EventPublicationInterceptor.ApplicationEventFactory.onFailure(MethodInvocation, Throwable) メソッドをオーバーライドすることでカスタマイズできます。

作成者:
Dmitriy Kopylenko, Juergen Hoeller, Rick Evans
関連事項:
  • コンストラクターの詳細

    • EventPublicationInterceptor

      public EventPublicationInterceptor()
  • メソッドの詳細

    • setApplicationEventClass

      public void setApplicationEventClass(ClassSE<? extends ApplicationEvent> applicationEventClass)
      呼び出しが成功するたびに公開するアプリケーションイベントクラスを設定します。

      イベントクラスに は、イベントソースの単一の Object 引数を持つコンストラクターが必要です。インターセプターは、呼び出されたオブジェクトを渡します。

      例外:
      IllegalArgumentExceptionSE - 指定された Class が null である場合、または ApplicationEvent サブクラスではない場合、単一の Object 引数を取るコンストラクターを公開していない場合
      関連事項:
    • setApplicationEventFactory

      public void setApplicationEventFactory(EventPublicationInterceptor.ApplicationEventFactory applicationEventFactory)
      成功した各メソッド呼び出しを表す、MethodInvocation から構築された ApplicationEvent インスタンスのファクトリ関数を指定します。
      導入:
      7.0.3
      関連事項:
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
      インターフェースからコピーされた説明: ApplicationEventPublisherAware
      このオブジェクトが実行される ApplicationEventPublisher を設定します。

      通常の Bean プロパティの設定後、InitializingBean の afterPropertiesSet などの init コールバックやカスタム init メソッドの前に呼び出されます。ApplicationContextAware の setApplicationContext の前に呼び出されます。

      次で指定:
      インターフェース ApplicationEventPublisherAwaresetApplicationEventPublisher 
      パラメーター:
      applicationEventPublisher - このオブジェクトによって使用されるイベント発行元
    • afterPropertiesSet

      public void afterPropertiesSet() throws ExceptionSE
      インターフェースからコピーされた説明: InitializingBean
      すべての Bean プロパティを設定し、BeanFactoryAwareApplicationContextAware などを満たした後、包含 BeanFactory によって呼び出されます。

      このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。

      次で指定:
      インターフェース InitializingBeanafterPropertiesSet 
      例外:
      ExceptionSE - 構成の誤り(必須プロパティの設定の失敗など)の場合、またはその他の理由で初期化が失敗した場合
    • invoke

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