Fail fast if spring.config.location uses unknown file extension
Closes gh-17241
This commit is contained in:
parent
572a436d1e
commit
0f105f7471
|
@ -453,6 +453,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
return;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("File extension of config file location '" + location
|
||||
+ "' is not known to any PropertySourceLoader");
|
||||
}
|
||||
Set<String> processed = new HashSet<>();
|
||||
for (PropertySourceLoader loader : this.propertySourceLoaders) {
|
||||
|
|
|
@ -65,6 +65,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigFileApplicationListener}.
|
||||
|
@ -981,6 +982,16 @@ class ConfigFileApplicationListenerTests {
|
|||
assertThat(this.environment.getProperty("gh17001loaded")).isEqualTo("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenConfigLocationSpecifiesUnknownFileExtensionConfigFileProcessingFailsFast() {
|
||||
String location = "classpath:application.unknown";
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
||||
"spring.config.location=" + location);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application))
|
||||
.withMessageContaining(location);
|
||||
}
|
||||
|
||||
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
|
||||
return new Condition<ConfigurableEnvironment>("environment containing property source " + sourceName) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue