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 c852eeb202..b0ff1155f1 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 @@ -62,6 +62,7 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -639,6 +640,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, for (String path : asResolvedSet(this.environment.getProperty(propertyName), null)) { if (!path.contains("$")) { path = StringUtils.cleanPath(path); + Assert.state(!path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX), + "Classpath wildard patterns cannot be used as a search location"); if (!ResourceUtils.isUrl(path)) { path = ResourceUtils.FILE_URL_PREFIX + path; } 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 742fa79edf..b5df9dac4c 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 @@ -698,6 +698,15 @@ class ConfigFileApplicationListenerTests { matchingPropertySource("applicationConfig: [file:" + location.replace(File.separatorChar, '/') + "]")); } + @Test + void classpathWildcardResourceThrowsException() { + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, + "spring.config.location=classpath*:override.properties"); + assertThatIllegalStateException() + .isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application)) + .withMessage("Classpath wildard patterns cannot be used as a search location"); + } + @Test void propertySourceAnnotation() { SpringApplication application = new SpringApplication(WithPropertySource.class);