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