Skip to content

Commit 9e6e200

Browse files
committed
Describe how to handle application events from descendant contexts
Closes gh-8899
1 parent c88559e commit 9e6e200

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ Application events are sent in the following order, as your application runs:
242242
TIP: You often won't need to use application events, but it can be handy to know that they
243243
exist. Internally, Spring Boot uses events to handle a variety of tasks.
244244

245+
Application events are sent using Spring Framework's event publishing mechanism. Part of
246+
this mechanism ensures that an event published to the listeners in a child context
247+
is also published to the listeners in any ancestors contexts. As a result of this, if
248+
your application uses a hierarchy of `SpringApplication` instances, a listener may
249+
receive multiple instances of the same type of application event.
250+
251+
To allow your listener to distinguish between an event for its context and an event for
252+
a descendant context, it should request that its application context is injected and
253+
then compare the injected context with context of the event. The context can be injected
254+
by implementing `ApplicationContextAware` or, if the listener is a bean, using `@Autowired`.
255+
245256

246257

247258
[[boot-features-web-environment]]

0 commit comments

Comments
 (0)