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:
parent
99f30700e2
commit
fb6568be73
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue