From fb6568be73955a03cd46ebf26a7fd1cdae205a77 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 3 Aug 2019 11:36:36 +0100 Subject: [PATCH] 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 --- .../context/config/ConfigFileApplicationListener.java | 3 ++- .../config/ConfigFileApplicationListenerTests.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 3c238fc028..1b0176655f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -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 processed = new HashSet<>(); for (PropertySourceLoader loader : this.propertySourceLoaders) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 2c13674ad9..3abec00e2e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -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 matchingPropertySource(final String sourceName) {