From fef62f784a7f07de11d37a00c23018c54b09c9ab Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 6 May 2021 18:08:29 -0700 Subject: [PATCH] Import profile specific files in correct order Update `StandardConfigDataLoader` to mark profile specific files with `Option.PROFILE` so that they are added in the correct order. This is a variation of the same issue described in commit 5774ea3f0c. Closes gh-26400 Co-authored-by: Scott Frederick Co-authored-by: Madhura Bhave --- .../boot/context/config/ConfigData.java | 18 +++++++++++++++--- .../config/StandardConfigDataLoader.java | 9 ++++++++- ...vironmentPostProcessorIntegrationTests.java | 8 ++++++++ ...-import-with-profile-variant-dev.properties | 1 + ...ith-profile-variant-imported-dev.properties | 1 + ...rt-with-profile-variant-imported.properties | 1 + ...tion-import-with-profile-variant.properties | 2 ++ 7 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-import-with-profile-variant-dev.properties create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-import-with-profile-variant-imported-dev.properties create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-import-with-profile-variant-imported.properties create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-import-with-profile-variant.properties diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java index fcb5eb83fc..d9e5a4be8f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java @@ -118,6 +118,13 @@ public final class ConfigData { @FunctionalInterface public interface PropertySourceOptions { + /** + * {@link PropertySourceOptions} instance that always returns + * {@link Options#NONE}. + * @since 2.4.6 + */ + PropertySourceOptions ALWAYS_NONE = new AlwaysPropertySourceOptions(Options.NONE); + /** * Return the options that should apply for the given property source. * @param propertySource the property source @@ -142,6 +149,9 @@ public final class ConfigData { * @return a new {@link PropertySourceOptions} instance */ static PropertySourceOptions always(Options options) { + if (options == Options.NONE) { + return ALWAYS_NONE; + } return new AlwaysPropertySourceOptions(options); } @@ -175,7 +185,7 @@ public final class ConfigData { /** * No options. */ - public static final Options NONE = Options.of(); + public static final Options NONE = new Options(Collections.emptySet()); private final Set