Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem configuring conditional sources for binder context with the DefaultCustomBinderFactory #3032

Closed
wants to merge 1 commit into from
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
Loading