Top Description Methods
org.springframework.context

public Interface ApplicationEventPublisher

Known Direct Subinterfaces
org.springframework.context.ApplicationContext
Annotations
@FunctionalInterface

Interface that encapsulates event publication functionality.

Serves as a super-interface for ApplicationContext.

Authors
Juergen Hoeller, Stephane Nicoll
Since
1.1.1
See Also
ApplicationContext, ApplicationEventPublisherAware, org.springframework.context.ApplicationEvent, org.springframework.context.event.ApplicationEventMulticaster, org.springframework.context.event.EventPublicationInterceptor, org.springframework.transaction.event.TransactionalApplicationListener

Method Summary

Modifier and TypeMethod and Description
public default void
publishEvent(ApplicationEvent
the event to publish
event
)

Notify all matching listeners registered with this application of an application event.

public void
publishEvent(Object
the event to publish
event
)

Notify all matching listeners registered with this application of an event.

Method Detail

publishEventback to summary
public default void publishEvent(ApplicationEvent event)

Notify all matching listeners registered with this application of an application event. Events may be framework events (such as ContextRefreshedEvent) or application-specific events.

Such an event publication step is effectively a hand-off to the multicaster and does not imply synchronous/asynchronous execution or even immediate execution at all. Event listeners are encouraged to be as efficient as possible, individually using asynchronous execution for longer-running and potentially blocking operations.

For usage in a reactive call stack, include event publication as a simple hand-off: Mono.fromRunnable(() -> eventPublisher.publishEvent(...)). As with any asynchronous execution, thread-local data is not going to be available for reactive listener methods. All state which is necessary to process the event needs to be included in the event instance itself.

For the convenient inclusion of the current transaction context in a reactive hand-off, consider using org.springframework.transaction.reactive.TransactionalEventPublisher#publishEvent(Function). For thread-bound transactions, this is not necessary since the state will be implicitly available through thread-local storage.

Parameters
event:ApplicationEvent

the event to publish

See Also
publishEvent(Object), ApplicationListener#supportsAsyncExecution(), org.springframework.context.event.ContextRefreshedEvent, org.springframework.context.event.ContextClosedEvent
publishEventback to summary
public void publishEvent(Object event)

Notify all matching listeners registered with this application of an event.

If the specified event is not an ApplicationEvent, it is wrapped in a PayloadApplicationEvent.

Such an event publication step is effectively a hand-off to the multicaster and does not imply synchronous/asynchronous execution or even immediate execution at all. Event listeners are encouraged to be as efficient as possible, individually using asynchronous execution for longer-running and potentially blocking operations.

For the convenient inclusion of the current transaction context in a reactive hand-off, consider using org.springframework.transaction.reactive.TransactionalEventPublisher#publishEvent(Object). For thread-bound transactions, this is not necessary since the state will be implicitly available through thread-local storage.

Parameters
event:Object

the event to publish

Since
4.2
See Also
publishEvent(ApplicationEvent), PayloadApplicationEvent