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
This commit is contained in:
Oleg Zhurakousky
2018-06-15 14:16:41 -04:00
parent 66b7d8dbe4
commit f3a18e6e83

View File

@@ -233,7 +233,15 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
}
ConfigurableApplicationContext binderProducingContext = springApplicationBuilder
.run(args.toArray(new String[args.size()]));
Binder<T, ?, ?> 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);