Interface ApplicationEventPublisher
- All Known Subinterfaces:
ApplicationContext
,ConfigurableApplicationContext
,ConfigurableWebApplicationContext
,WebApplicationContext
- All Known Implementing Classes:
AbstractApplicationContext
,AbstractRefreshableApplicationContext
,AbstractRefreshableConfigApplicationContext
,AbstractRefreshableWebApplicationContext
,AbstractXmlApplicationContext
,AnnotationConfigApplicationContext
,AnnotationConfigWebApplicationContext
,ClassPathXmlApplicationContext
,FileSystemXmlApplicationContext
,GenericApplicationContext
,GenericGroovyApplicationContext
,GenericWebApplicationContext
,GenericXmlApplicationContext
,GroovyWebApplicationContext
,StaticApplicationContext
,StaticWebApplicationContext
,XmlWebApplicationContext
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Serves as a super-interface for ApplicationContext
.
- Since:
- 1.1.1
- Author:
- Juergen Hoeller, Stephane Nicoll
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
publishEvent
(Object event) Notify all matching listeners registered with this application of an event.default void
publishEvent
(ApplicationEvent event) Notify all matching listeners registered with this application of an application event.
-
Method Details
-
publishEvent
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
TransactionalEventPublisher.publishEvent(Function)
. For thread-bound transactions, this is not necessary since the state will be implicitly available through thread-local storage.- Parameters:
event
- the event to publish- See Also:
-
publishEvent
Notify all matching listeners registered with this application of an event.If the specified
event
is not anApplicationEvent
, it is wrapped in aPayloadApplicationEvent
.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
TransactionalEventPublisher.publishEvent(Object)
. For thread-bound transactions, this is not necessary since the state will be implicitly available through thread-local storage.- Parameters:
event
- the event to publish- Since:
- 4.2
- See Also:
-