Change order of the registry of sources classes after configuring Environment with all propertySources, so that sources classes can resolve conditions configurations. Fixes GH-3031
Resolves #3032
This commit is contained in:
committed by
Oleg Zhurakousky
parent
286d686542
commit
9fc31b3674
@@ -438,23 +438,6 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
|
||||
binderProducingContext.getBeanFactory().setConversionService(this.context.getBeanFactory().getConversionService());
|
||||
}
|
||||
|
||||
List<Class> sourceClasses = new ArrayList<>();
|
||||
sourceClasses.addAll(Arrays.asList(binderType.getConfigurationClasses()));
|
||||
if (binderProperties.containsKey("spring.main.sources")) {
|
||||
String sources = (String) binderProperties.get("spring.main.sources");
|
||||
if (StringUtils.hasText(sources)) {
|
||||
Stream.of(sources.split(",")).forEach(source -> {
|
||||
try {
|
||||
sourceClasses.add(Thread.currentThread().getContextClassLoader().loadClass(source.trim()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to load class " + source, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
binderProducingContext.register(sourceClasses.toArray(new Class[] {}));
|
||||
MapPropertySource binderPropertySource = new MapPropertySource(configurationName, binderProperties);
|
||||
binderProducingContext.getEnvironment().getPropertySources().addFirst(binderPropertySource);
|
||||
binderProducingContext.setDisplayName(configurationName + "_context");
|
||||
@@ -494,6 +477,23 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
|
||||
}
|
||||
}
|
||||
|
||||
// Register the sources classes to the specific binder context after configuring the environment property sources
|
||||
List<Class> sourceClasses = new ArrayList<>(Arrays.asList(binderType.getConfigurationClasses()));
|
||||
if (binderProperties.containsKey("spring.main.sources")) {
|
||||
String sources = (String) binderProperties.get("spring.main.sources");
|
||||
if (StringUtils.hasText(sources)) {
|
||||
Stream.of(sources.split(",")).forEach(source -> {
|
||||
try {
|
||||
sourceClasses.add(Thread.currentThread().getContextClassLoader().loadClass(source.trim()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to load class " + source, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
binderProducingContext.register(sourceClasses.toArray(new Class[] {}));
|
||||
|
||||
if (refresh) {
|
||||
if (!useApplicationContextAsParent || "integration".equals(binderType.getDefaultName())) {
|
||||
this.propagateSharedBeans(binderProducingContext, (GenericApplicationContext) this.context);
|
||||
|
||||
Reference in New Issue
Block a user