Skip to content

Commit fb6568b

Browse files
committed
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
1 parent 99f3070 commit fb6568b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ private void load(String location, String name, Profile profile, DocumentFilterF
454454
}
455455
}
456456
throw new IllegalStateException("File extension of config file location '" + location
457-
+ "' is not known to any PropertySourceLoader");
457+
+ "' is not known to any PropertySourceLoader. If the location is meant to reference "
458+
+ "a directory, it must end in '/'");
458459
}
459460
Set<String> processed = new HashSet<>();
460461
for (PropertySourceLoader loader : this.propertySourceLoaders) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,16 @@ void whenConfigLocationSpecifiesUnknownFileExtensionConfigFileProcessingFailsFas
989989
"spring.config.location=" + location);
990990
assertThatIllegalStateException()
991991
.isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application))
992-
.withMessageContaining(location);
992+
.withMessageContaining(location)
993+
.withMessageContaining("If the location is meant to reference a directory, it must end in '/'");
994+
}
995+
996+
@Test
997+
void whenConfigLocationSpecifiesFolderConfigFileProcessingContinues() {
998+
String location = "classpath:application.unknown/";
999+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
1000+
"spring.config.location=" + location);
1001+
this.initializer.postProcessEnvironment(this.environment, this.application);
9931002
}
9941003

9951004
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {

0 commit comments

Comments
 (0)