spring-framework / org.springframework.context.event

Package org.springframework.context.event

Types

ApplicationListenerMethodAdapter

open class ApplicationListenerMethodAdapter : GenericApplicationListener

GenericApplicationListener adapter that delegates the processing of an event to an EventListener annotated method.

Delegates to #processEvent(ApplicationEvent) to give sub-classes a chance to deviate from the default. Unwraps the content of a PayloadApplicationEvent if necessary to allow method declaration to define any arbitrary event type. If a condition is defined, it is evaluated prior to invoking the underlying method.

ContextClosedEvent

open class ContextClosedEvent : ApplicationContextEvent

Event raised when an ApplicationContext gets closed.

ContextRefreshedEvent

open class ContextRefreshedEvent : ApplicationContextEvent

Event raised when an ApplicationContext gets initialized or refreshed.

ContextStartedEvent

open class ContextStartedEvent : ApplicationContextEvent

Event raised when an ApplicationContext gets started.

ContextStoppedEvent

open class ContextStoppedEvent : ApplicationContextEvent

Event raised when an ApplicationContext gets stopped.

DefaultEventListenerFactory

open class DefaultEventListenerFactory : EventListenerFactory, Ordered

Default EventListenerFactory implementation that supports the regular EventListener annotation.

Used as "catch-all" implementation by default.

EventListenerMethodProcessor

open class EventListenerMethodProcessor : SmartInitializingSingleton, ApplicationContextAware

Register EventListener annotated method as individual ApplicationListener instances.

EventPublicationInterceptor

open class EventPublicationInterceptor : MethodInterceptor, ApplicationEventPublisherAware, InitializingBean

MethodInterceptor that publishes an ApplicationEvent to all ApplicationListeners registered with an ApplicationEventPublisher after each successful method invocation.

Note that this interceptor is only capable of publishing stateless events configured via the "applicationEventClass" property.

GenericApplicationListenerAdapter

open class GenericApplicationListenerAdapter : GenericApplicationListener, SmartApplicationListener

GenericApplicationListener adapter that determines supported event types through introspecting the generically declared type of the target listener.

SimpleApplicationEventMulticaster

open class SimpleApplicationEventMulticaster : AbstractApplicationEventMulticaster

Simple implementation of the ApplicationEventMulticaster interface.

Multicasts all events to all registered listeners, leaving it up to the listeners to ignore events that they are not interested in. Listeners will usually perform corresponding instanceof checks on the passed-in event object.

By default, all listeners are invoked in the calling thread. This allows the danger of a rogue listener blocking the entire application, but adds minimal overhead. Specify an alternative task executor to have listeners executed in different threads, for example from a thread pool.

SmartApplicationListener

interface SmartApplicationListener : ApplicationListener<ApplicationEvent>, Ordered

Extended variant of the standard ApplicationListener interface, exposing further metadata such as the supported event type.

Users are strongly advised to use the GenericApplicationListener interface instead as it provides an improved detection of generics-based event types.

SourceFilteringListener

open class SourceFilteringListener : GenericApplicationListener, SmartApplicationListener

org.springframework.context.ApplicationListener decorator that filters events from a specified event source, invoking its delegate listener for matching org.springframework.context.ApplicationEvent objects only.

Can also be used as base class, overriding the #onApplicationEventInternal method instead of specifying a delegate listener.

Annotations

EventListener

class EventListener

Annotation that marks a method as a listener for application events.

If an annotated method supports a single event type, the method may declare a single parameter that reflects the event type to listen to. If an annotated method supports multiple event types, this annotation may refer to one or more supported event types using the classes attribute. See the #classes javadoc for further details.

Events can be ApplicationEvent instances as well as arbitrary objects.

Processing of @EventListener annotations is performed via the internal EventListenerMethodProcessor bean which gets registered automatically when using Java config or manually via the <context:annotation-config/> or <context:component-scan/> element when using XML config.

Annotated methods may have a non-void return type. When they do, the result of the method invocation is sent as a new event. If the return type is either an array or a collection, each element is sent as a new individual event.

It is also possible to define the order in which listeners for a certain event are to be invoked. To do so, add Spring's common org.springframework.core.annotation.Order annotation alongside this event listener annotation.

While it is possible for an event listener to declare that it throws arbitrary exception types, any checked exceptions thrown from an event listener will be wrapped in an java.lang.reflect.UndeclaredThrowableException since the event publisher can only handle runtime exceptions.