From 0f105f747124f5ea349b7148f8e8c3e22d0865f6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 18 Jul 2019 15:33:34 +0100 Subject: [PATCH] Fail fast if spring.config.location uses unknown file extension Closes gh-17241 --- .../context/config/ConfigFileApplicationListener.java | 2 ++ .../config/ConfigFileApplicationListenerTests.java | 11 +++++++++++ 2 files changed, 13 insertions(+) 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 f17e20f257..3c238fc028 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 @@ -453,6 +453,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, return; } } + throw new IllegalStateException("File extension of config file location '" + location + + "' is not known to any PropertySourceLoader"); } 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 a4a261fd97..2c13674ad9 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 @@ -65,6 +65,7 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link ConfigFileApplicationListener}. @@ -981,6 +982,16 @@ class ConfigFileApplicationListenerTests { assertThat(this.environment.getProperty("gh17001loaded")).isEqualTo("true"); } + @Test + void whenConfigLocationSpecifiesUnknownFileExtensionConfigFileProcessingFailsFast() { + String location = "classpath:application.unknown"; + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, + "spring.config.location=" + location); + assertThatIllegalStateException() + .isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application)) + .withMessageContaining(location); + } + private Condition matchingPropertySource(final String sourceName) { return new Condition("environment containing property source " + sourceName) {