Class EventPublicationInterceptor

java.lang.Object
org.springframework.context.event.EventPublicationInterceptor
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, Aware, InitializingBean, ApplicationEventPublisherAware

public class EventPublicationInterceptor extends Object implements MethodInterceptor, ApplicationEventPublisherAware, InitializingBean
Interceptor that publishes an ApplicationEvent to all ApplicationListeners registered with an ApplicationEventPublisher after each successful method invocation.

Note that this interceptor is capable of publishing a custom event after each successful method invocation, configured via the "applicationEventClass" property. As of 7.0.3, you can configure a factory function instead, implementing the primary EventPublicationInterceptor.ApplicationEventFactory.onSuccess(MethodInvocation, Object) method there.

By default (as of 7.0.3), this interceptor publishes a MethodFailureEvent for every exception encountered from a method invocation. This can be conveniently tracked via an ApplicationListener<MethodFailureEvent> class or an @EventListener(MethodFailureEvent.class) method. The failure event can be customized through overriding the EventPublicationInterceptor.ApplicationEventFactory.onFailure(MethodInvocation, Throwable) method.

Author:
Dmitriy Kopylenko, Juergen Hoeller, Rick Evans
See Also:
  • Constructor Details

    • EventPublicationInterceptor

      public EventPublicationInterceptor()
  • Method Details