From 7f32fa6723cd5d0b63a44032445a9afb9121457f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 27 Jan 2021 14:07:02 -0800 Subject: [PATCH] Allow 'on-profile' in profile specific files Restore the ability to use `spring.config.activate.on-profile` or `spring.profiles` in profile specific files. Closes gh-24990 --- .../config/InvalidConfigDataPropertyException.java | 2 -- ...nfigDataEnvironmentPostProcessorIntegrationTests.java | 9 +++++++++ .../config/InvalidConfigDataPropertyExceptionTests.java | 2 -- ...e-on-profile-in-profile-specific-file-test.properties | 4 ++++ ...tivate-on-profile-in-profile-specific-file.properties | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file-test.properties create mode 100644 spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file.properties diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/InvalidConfigDataPropertyException.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/InvalidConfigDataPropertyException.java index 21be4abaac37..9e3e03af42b7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/InvalidConfigDataPropertyException.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/InvalidConfigDataPropertyException.java @@ -52,8 +52,6 @@ public class InvalidConfigDataPropertyException extends ConfigDataException { errors.add(Profiles.INCLUDE_PROFILES); errors.add(ConfigurationPropertyName.of(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)); errors.add(ConfigurationPropertyName.of(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME)); - errors.add(ConfigurationPropertyName.of("spring.config.activate.on-profile")); - errors.add(ConfigurationPropertyName.of("spring.profiles")); PROFILE_SPECIFIC_ERRORS = Collections.unmodifiableSet(errors); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java index 1d8f3a5419bb..bba8dd5d12f3 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java @@ -680,6 +680,15 @@ void runWhenHasWildcardLocationLoadsFromAllMatchingLocations() { assertThat(environment.getProperty("second.property")).isEqualTo("ball"); } + @Test // gh-24990 + void runWhenHasProfileSpecificFileWithActiveOnProfileProperty() { + ConfigurableApplicationContext context = this.application + .run("--spring.config.name=application-activate-on-profile-in-profile-specific-file"); + ConfigurableEnvironment environment = context.getEnvironment(); + assertThat(environment.getProperty("test1")).isEqualTo("test1"); + assertThat(environment.getProperty("test2")).isEqualTo("test2"); + } + private Condition matchingPropertySource(final String sourceName) { return new Condition("environment containing property source " + sourceName) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java index fae33cb88003..e104a9719cb9 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java @@ -125,8 +125,6 @@ void throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException() { throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.include"); throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.active"); throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.default"); - throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.config.activate.on-profile"); - throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file-test.properties b/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file-test.properties new file mode 100644 index 000000000000..36e382cb6cdf --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file-test.properties @@ -0,0 +1,4 @@ +test1=test1 +#--- +spring.config.activate.on-profile=other +test2=test2 diff --git a/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file.properties b/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file.properties new file mode 100644 index 000000000000..d7ec8875c8cd --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/resources/application-activate-on-profile-in-profile-specific-file.properties @@ -0,0 +1 @@ +spring.profiles.active=test,other