From e23a6078a7d8cd59096708f048604c5e2948c114 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 6 Jan 2023 08:40:50 +0100 Subject: [PATCH] GH-2596 Ensure that bean propagation between binder and app context is timely Resolves #2596 --- .../cloud/stream/binder/DefaultBinderFactory.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java index 3a5ae5ee4..6ff5ae06f 100644 --- a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java +++ b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java @@ -423,7 +423,6 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl binderProducingContext.setParent(this.context); } else if (this.context != null) { - this.propagateSharedBeans((GenericApplicationContext) this.context, binderProducingContext); binderProducingContext.addApplicationListener(new ApplicationListener() { @Override public void onApplicationEvent(ApplicationEvent event) { @@ -455,14 +454,18 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl if (refresh) { binderProducingContext.refresh(); + if (!useApplicationContextAsParent || "integration".equals(binderType.getDefaultName())) { + this.propagateSharedBeans((GenericApplicationContext) this.context, binderProducingContext); + } } - if ("integration".equals(binderType.getDefaultName())) { - this.propagateSharedBeans((GenericApplicationContext) this.context, binderProducingContext); - } + return binderProducingContext; } private void propagateSharedBeans(GenericApplicationContext toContext, GenericApplicationContext fromContext) { + if (toContext == null) { + return; + } GenericConversionService binderProducingConversionService = (GenericConversionService) toContext.getBeanFactory().getConversionService(); try { Enumeration resources = ClassUtils.getDefaultClassLoader().getResources("META-INF/shared.beans");