GH-2788: Outer context bean needed for AOT

OuterContext bean is added to application context for AOT.
This bean is needed when the actuator dependency is added.

Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2788
This commit is contained in:
omercelik
2023-08-11 11:25:03 +03:00
committed by Soby Chacko
parent aa0e9af3ff
commit fbecaaa5ca

View File

@@ -74,6 +74,7 @@ import org.springframework.util.StringUtils;
* @author Anshul Mehra
* @author Chris Bono
* @author Byungjun You
* @author Omer Celik
*/
public class DefaultBinderFactory implements BinderFactory, DisposableBean, ApplicationContextAware {
@@ -323,6 +324,7 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
}
binderProducingContext = this.createUnitializedContextForAOT(configurationName, binderProperties, binderConfiguration);
this.binderChildContextInitializers.get(configurationName).initialize(binderProducingContext);
registerOuterContextBean(binderProperties, binderProducingContext);
binderProducingContext.refresh();
}
else {
@@ -578,6 +580,17 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
return binderContext;
}
private void registerOuterContextBean(Map<String, Object> binderProperties, ConfigurableApplicationContext binderProducingContext) {
ConfigurableEnvironment environment = this.context != null
? this.context.getEnvironment() : null;
boolean useApplicationContextAsParent = binderProperties.isEmpty()
&& this.context != null;
if (environment != null && !useApplicationContextAsParent) {
InitializerWithOuterContext initializer = new InitializerWithOuterContext(this.context);
initializer.initialize(binderProducingContext);
}
}
/**
* Ensures that nested properties are flattened (i.e., foo.bar=baz instead of
* foo={bar=baz}).