Fail hard if spring.profiles.include is used with new config processing
Closes gh-22693
This commit is contained in:
@@ -35,7 +35,7 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyS
|
||||
*/
|
||||
public class InvalidConfigDataPropertyException extends ConfigDataException {
|
||||
|
||||
private static final Map<ConfigurationPropertyName, ConfigurationPropertyName> ERROR = Collections.emptyMap();
|
||||
private static final Map<ConfigurationPropertyName, ConfigurationPropertyName> ERROR;
|
||||
|
||||
private static final Map<ConfigurationPropertyName, ConfigurationPropertyName> WARNING;
|
||||
static {
|
||||
@@ -43,6 +43,10 @@ public class InvalidConfigDataPropertyException extends ConfigDataException {
|
||||
warning.put(ConfigurationPropertyName.of("spring.profiles"),
|
||||
ConfigurationPropertyName.of("spring.config.activate.on-profile"));
|
||||
WARNING = Collections.unmodifiableMap(warning);
|
||||
Map<ConfigurationPropertyName, ConfigurationPropertyName> error = new LinkedHashMap<>();
|
||||
error.put(ConfigurationPropertyName.of("spring.profiles.include"),
|
||||
ConfigurationPropertyName.of("spring.profiles.group"));
|
||||
ERROR = Collections.unmodifiableMap(error);
|
||||
}
|
||||
|
||||
private final ConfigurationProperty property;
|
||||
|
||||
@@ -123,6 +123,17 @@ class InvalidConfigDataPropertyExceptionTests {
|
||||
+ "'spring.config.activate.on-profile' [origin: \"spring.profiles\" from property source \"mockProperties\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void throwOrWarnWhenHasErrorPropertyThrowsException() {
|
||||
MockPropertySource propertySource = new MockPropertySource();
|
||||
propertySource.setProperty("spring.profiles.include", "a");
|
||||
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(propertySource);
|
||||
assertThatExceptionOfType(InvalidConfigDataPropertyException.class)
|
||||
.isThrownBy(() -> InvalidConfigDataPropertyException.throwOrWarn(this.logger, contributor))
|
||||
.withMessage("Property 'spring.profiles.include' is invalid and should be replaced with "
|
||||
+ "'spring.profiles.group' [origin: \"spring.profiles.include\" from property source \"mockProperties\"]");
|
||||
}
|
||||
|
||||
private static class TestConfigDataLocation extends ConfigDataLocation {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user