diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java index 77abf8d2d9d..c7aeae88d42 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java @@ -17,6 +17,7 @@ package org.springframework.boot.context.config; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; @@ -57,6 +58,7 @@ import org.springframework.util.StringUtils; * * @author Phillip Webb * @author Madhura Bhave + * @author Nan Chiu */ class ConfigDataEnvironment { @@ -197,7 +199,8 @@ class ConfigDataEnvironment { private List getInitialImportContributors(Binder binder) { List initialContributors = new ArrayList<>(); - addInitialImportContributors(initialContributors, bindLocations(binder, IMPORT_PROPERTY, EMPTY_LOCATIONS)); + addInitialImportPropertyContributors(initialContributors, + bindLocations(binder, IMPORT_PROPERTY, EMPTY_LOCATIONS)); addInitialImportContributors(initialContributors, bindLocations(binder, ADDITIONAL_LOCATION_PROPERTY, EMPTY_LOCATIONS)); addInitialImportContributors(initialContributors, @@ -209,6 +212,15 @@ class ConfigDataEnvironment { return binder.bind(propertyName, CONFIG_DATA_LOCATION_ARRAY).orElse(other); } + private void addInitialImportPropertyContributors(List initialContributors, + ConfigDataLocation[] locations) { + List initialPropertiesContributors = new ArrayList<>(); + addInitialImportContributors(initialPropertiesContributors, locations); + initialContributors.add(ConfigDataEnvironmentContributor.ofInitialImportProperty( + initialPropertiesContributors, this.environment.getConversionService(), Arrays.asList(locations)) + ); + } + private void addInitialImportContributors(List initialContributors, ConfigDataLocation[] locations) { for (int i = locations.length - 1; i >= 0; i--) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java index 3c85a5b9ed9..0e1af5e8ef7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java @@ -52,6 +52,7 @@ import org.springframework.util.CollectionUtils; * * @author Phillip Webb * @author Madhura Bhave + * @author Nan Chiu */ class ConfigDataEnvironmentContributor implements Iterable { @@ -404,6 +405,27 @@ class ConfigDataEnvironmentContributor implements Iterable contributors, + ConversionService conversionService, + List locations) { + Map> children = new LinkedHashMap<>(); + ConfigDataProperties properties = new ConfigDataProperties(locations, null); + children.put(ImportPhase.BEFORE_PROFILE_ACTIVATION, Collections.unmodifiableList(contributors)); + return new ConfigDataEnvironmentContributor(Kind.INITIAL_IMPORT_PROPERTY, null, null, false, null, null, properties, null, children, + conversionService); + } + /** * Factory method to create a contributor that wraps an {@link Kind#EXISTING existing} * property source. The contributor provides access to existing properties, but @@ -477,6 +499,11 @@ class ConfigDataEnvironmentContributor implements Iterable