Commit fb6568be authored by Phillip Webb's avatar Phillip Webb

Improve PropertySourceLoader file extension error

Refine the `IllegalStateException` thrown from `PropertySourceLoader`
for unknown extensions to also indicated that folder references must end
in '/'.

Closes gh-17241
parent 99f30700
......@@ -454,7 +454,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
}
throw new IllegalStateException("File extension of config file location '" + location
+ "' is not known to any PropertySourceLoader");
+ "' is not known to any PropertySourceLoader. If the location is meant to reference "
+ "a directory, it must end in '/'");
}
Set<String> processed = new HashSet<>();
for (PropertySourceLoader loader : this.propertySourceLoaders) {
......
......@@ -989,7 +989,16 @@ class ConfigFileApplicationListenerTests {
"spring.config.location=" + location);
assertThatIllegalStateException()
.isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application))
.withMessageContaining(location);
.withMessageContaining(location)
.withMessageContaining("If the location is meant to reference a directory, it must end in '/'");
}
@Test
void whenConfigLocationSpecifiesFolderConfigFileProcessingContinues() {
String location = "classpath:application.unknown/";
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
"spring.config.location=" + location);
this.initializer.postProcessEnvironment(this.environment, this.application);
}
private Condition<ConfigurableEnvironment> matchingPropertySource(final String 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