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
This commit is contained in:
Phillip Webb 2019-08-03 11:36:36 +01:00
parent 99f30700e2
commit fb6568be73
2 changed files with 12 additions and 2 deletions

View File

@ -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) {

View File

@ -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) {