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
This commit is contained in:
Oleg Zhurakousky
2020-01-10 14:03:52 +01:00
parent d7c2b7aed8
commit 51e8d73116

View File

@@ -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<ApplicationEvent>() {
@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.