Skip to content

Commit 36b082e

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-21174
2 parents 0761ff1 + e2705b2 commit 36b082e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.springframework.core.io.DefaultResourceLoader;
6363
import org.springframework.core.io.Resource;
6464
import org.springframework.core.io.ResourceLoader;
65+
import org.springframework.core.io.support.ResourcePatternResolver;
6566
import org.springframework.core.io.support.SpringFactoriesLoader;
6667
import org.springframework.util.Assert;
6768
import org.springframework.util.CollectionUtils;
@@ -639,6 +640,8 @@ private Set<String> getSearchLocations(String propertyName) {
639640
for (String path : asResolvedSet(this.environment.getProperty(propertyName), null)) {
640641
if (!path.contains("$")) {
641642
path = StringUtils.cleanPath(path);
643+
Assert.state(!path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX),
644+
"Classpath wildard patterns cannot be used as a search location");
642645
if (!ResourceUtils.isUrl(path)) {
643646
path = ResourceUtils.FILE_URL_PREFIX + path;
644647
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,15 @@ void absoluteResourceDefaultsToFile() {
698698
matchingPropertySource("applicationConfig: [file:" + location.replace(File.separatorChar, '/') + "]"));
699699
}
700700

701+
@Test
702+
void classpathWildcardResourceThrowsException() {
703+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
704+
"spring.config.location=classpath*:override.properties");
705+
assertThatIllegalStateException()
706+
.isThrownBy(() -> this.initializer.postProcessEnvironment(this.environment, this.application))
707+
.withMessage("Classpath wildard patterns cannot be used as a search location");
708+
}
709+
701710
@Test
702711
void propertySourceAnnotation() {
703712
SpringApplication application = new SpringApplication(WithPropertySource.class);

0 commit comments

Comments
 (0)