クラス EventPublicationInterceptor
- 実装されているすべてのインターフェース:
Advice, Interceptor, MethodInterceptor, Aware, InitializingBean, ApplicationEventPublisherAware
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
- 関連事項:
ネストされたクラスの要約
ネストされたクラスコンストラクターの概要
コンストラクター方法の概要
修飾子と型メソッド説明voidinvoke(MethodInvocation invocation) このメソッドを実装して、呼び出しの前後に追加の処理を実行します。voidsetApplicationEventClass(ClassSE<? extends ApplicationEvent> applicationEventClass) 呼び出しが成功するたびに公開するアプリケーションイベントクラスを設定します。voidsetApplicationEventFactory(EventPublicationInterceptor.ApplicationEventFactory applicationEventFactory) 成功した各メソッド呼び出しを表す、MethodInvocationから構築されたApplicationEventインスタンスのファクトリ関数を指定します。voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) このオブジェクトが実行される ApplicationEventPublisher を設定します。
コンストラクターの詳細
EventPublicationInterceptor
public EventPublicationInterceptor()
メソッドの詳細
setApplicationEventClass
呼び出しが成功するたびに公開するアプリケーションイベントクラスを設定します。イベントクラスに は、イベントソースの単一の
Object引数を持つコンストラクターが必要です。インターセプターは、呼び出されたオブジェクトを渡します。- 例外:
IllegalArgumentExceptionSE- 指定されたClassがnullである場合、またはApplicationEventサブクラスではない場合、単一のObject引数を取るコンストラクターを公開していない場合- 関連事項:
setApplicationEventFactory
public void setApplicationEventFactory(EventPublicationInterceptor.ApplicationEventFactory applicationEventFactory) 成功した各メソッド呼び出しを表す、MethodInvocationから構築されたApplicationEventインスタンスのファクトリ関数を指定します。- 導入:
- 7.0.3
- 関連事項:
setApplicationEventPublisher
インターフェースからコピーされた説明:ApplicationEventPublisherAwareこのオブジェクトが実行される ApplicationEventPublisher を設定します。通常の Bean プロパティの設定後、InitializingBean の afterPropertiesSet などの init コールバックやカスタム init メソッドの前に呼び出されます。ApplicationContextAware の setApplicationContext の前に呼び出されます。
- 次で指定:
- インターフェース
ApplicationEventPublisherAwareのsetApplicationEventPublisher - パラメーター:
applicationEventPublisher- このオブジェクトによって使用されるイベント発行元
afterPropertiesSet
インターフェースからコピーされた説明:InitializingBeanすべての Bean プロパティを設定し、BeanFactoryAware、ApplicationContextAwareなどを満たした後、包含BeanFactoryによって呼び出されます。このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。
- 次で指定:
- インターフェース
InitializingBeanのafterPropertiesSet - 例外:
ExceptionSE- 構成の誤り(必須プロパティの設定の失敗など)の場合、またはその他の理由で初期化が失敗した場合
invoke
インターフェースからコピーされた説明:MethodInterceptorこのメソッドを実装して、呼び出しの前後に追加の処理を実行します。正しい実装としては、必ずJoinpoint.proceed()を呼び出すようにします。- 次で指定:
- インターフェース
MethodInterceptorのinvoke - パラメーター:
invocation- メソッド呼び出しジョインポイント- 戻り値:
Joinpoint.proceed()の呼び出しの結果。インターセプターによってインターセプトされる可能性があります- 例外:
ThrowableSE- インターセプターまたはターゲットオブジェクトが例外をスローする場合