From 9e6e200d8d5dacbc55e84dad9a73d3ccd20e7a28 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 20 Oct 2017 10:29:06 +0100 Subject: [PATCH] Describe how to handle application events from descendant contexts Closes gh-8899 --- .../src/main/asciidoc/spring-boot-features.adoc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 414566dde8..b189c915df 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -242,6 +242,17 @@ Application events are sent in the following order, as your application runs: TIP: You often won't need to use application events, but it can be handy to know that they exist. Internally, Spring Boot uses events to handle a variety of tasks. +Application events are sent using Spring Framework's event publishing mechanism. Part of +this mechanism ensures that an event published to the listeners in a child context +is also published to the listeners in any ancestors contexts. As a result of this, if +your application uses a hierarchy of `SpringApplication` instances, a listener may +receive multiple instances of the same type of application event. + +To allow your listener to distinguish between an event for its context and an event for +a descendant context, it should request that its application context is injected and +then compare the injected context with context of the event. The context can be injected +by implementing `ApplicationContextAware` or, if the listener is a bean, using `@Autowired`. + [[boot-features-web-environment]]