Skip to content

Commit

Permalink
Allow 'on-profile' in profile specific files
Browse files Browse the repository at this point in the history
Restore the ability to use `spring.config.activate.on-profile` or
`spring.profiles` in profile specific files.

Closes gh-24990
  • Loading branch information
philwebb committed Jan 27, 2021
1 parent d06407e commit 7f32fa6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
return new Condition<ConfigurableEnvironment>("environment containing property source " + sourceName) {

Expand Down
Expand Up @@ -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
Expand Down
@@ -0,0 +1,4 @@
test1=test1
#---
spring.config.activate.on-profile=other
test2=test2
@@ -0,0 +1 @@
spring.profiles.active=test,other

0 comments on commit 7f32fa6

Please sign in to comment.