Commit 0f105f74 authored by Andy Wilkinson's avatar Andy Wilkinson

Fail fast if spring.config.location uses unknown file extension

Closes gh-17241
parent 572a436d
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment