Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,6 @@ ConfigurableApplicationContext initializeBinderContextSimple(String configuratio
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");
Expand Down Expand Up @@ -502,6 +485,23 @@ public void onApplicationEvent(ApplicationEvent event) {
}
}

// 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);
Expand Down