From f3a18e6e83f559f2d58de6e48dd9c56a466a5b84 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 15 Jun 2018 14:16:41 -0400 Subject: [PATCH] GH-1384 Set application's context as binder context Set application's context as binder context once the binder is initialized to ensure identical behavior in i multi-environment scenarios. Resolves #1384 Resolves #1357 --- .../cloud/stream/binder/DefaultBinderFactory.java | 8 ++++++++ 1 file changed, 8 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 509a520be..f11f9c66d 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 @@ -233,7 +233,15 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl } ConfigurableApplicationContext binderProducingContext = springApplicationBuilder .run(args.toArray(new String[args.size()])); + Binder binder = binderProducingContext.getBean(Binder.class); + /* + * This will ensure that application defined errorChannel and other beans are accessible within binder's context + * (see https://github.com/spring-cloud/spring-cloud-stream/issues/1384) + */ + if (this.context != null && binder instanceof ApplicationContextAware) { + ((ApplicationContextAware)binder).setApplicationContext(this.context); + } if (!CollectionUtils.isEmpty(this.listeners)) { for (Listener binderFactoryListener : listeners) { binderFactoryListener.afterBinderContextInitialized(configurationName, binderProducingContext);