GH-2596 Ensure that bean propagation between binder and app context is timely

Resolves #2596
This commit is contained in:
Oleg Zhurakousky
2023-01-06 08:40:50 +01:00
parent a9196584d2
commit e23a6078a7

View File

@@ -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<ApplicationEvent>() {
@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<URL> resources = ClassUtils.getDefaultClassLoader().getResources("META-INF/shared.beans");