From 51e8d731169097cd078b648d607d27017a916ae4 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 10 Jan 2020 14:03:52 +0100 Subject: [PATCH] GH-1880 Fixed application event propagation Whe framework creates child context it contains different set of listeners then the ones that are in parent. Such child context was created whenevr explicit binder 'environment' was provided. And because BindingCreatedEvent was fired on parent application context it was never acted upon thus preventing subscription on the reactive Supplier Resolves #1880 --- .../cloud/stream/binder/DefaultBinderFactory.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java index dd7160ca0..ba615535d 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java @@ -36,6 +36,8 @@ import org.springframework.cloud.stream.reflection.GenericsUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; @@ -273,6 +275,16 @@ public class DefaultBinderFactory if (useApplicationContextAsParent) { springApplicationBuilder.parent(this.context); } + else { + springApplicationBuilder.listeners(new ApplicationListener() { + @Override + public void onApplicationEvent(ApplicationEvent event) { + if (context != null) { + context.publishEvent(event); + } + } + }); + } // If the current application context is not set as parent and the environment // is set, // provide the current context as an additional bean in the BeanFactory.