File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/context/config
test/java/org/springframework/boot/context/config Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 6262import org .springframework .core .io .DefaultResourceLoader ;
6363import org .springframework .core .io .Resource ;
6464import org .springframework .core .io .ResourceLoader ;
65+ import org .springframework .core .io .support .ResourcePatternResolver ;
6566import org .springframework .core .io .support .SpringFactoriesLoader ;
6667import org .springframework .util .Assert ;
6768import org .springframework .util .CollectionUtils ;
@@ -618,6 +619,8 @@ private Set<String> getSearchLocations(String propertyName) {
618619 for (String path : asResolvedSet (this .environment .getProperty (propertyName ), null )) {
619620 if (!path .contains ("$" )) {
620621 path = StringUtils .cleanPath (path );
622+ Assert .state (!path .startsWith (ResourcePatternResolver .CLASSPATH_ALL_URL_PREFIX ),
623+ "Classpath wildard patterns cannot be used as a search location" );
621624 if (!ResourceUtils .isUrl (path )) {
622625 path = ResourceUtils .FILE_URL_PREFIX + path ;
623626 }
Original file line number Diff line number Diff line change 6363import org .springframework .util .StringUtils ;
6464
6565import static org .assertj .core .api .Assertions .assertThat ;
66+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
6667
6768/**
6869 * Tests for {@link ConfigFileApplicationListener}.
@@ -648,6 +649,15 @@ public void absoluteResourceDefaultsToFile() {
648649 matchingPropertySource ("applicationConfig: [file:" + location .replace (File .separatorChar , '/' ) + "]" ));
649650 }
650651
652+ @ Test
653+ public void classpathWildcardResourceThrowsException () {
654+ TestPropertySourceUtils .addInlinedPropertiesToEnvironment (this .environment ,
655+ "spring.config.location=classpath*:override.properties" );
656+ assertThatIllegalStateException ()
657+ .isThrownBy (() -> this .initializer .postProcessEnvironment (this .environment , this .application ))
658+ .withMessage ("Classpath wildard patterns cannot be used as a search location" );
659+ }
660+
651661 @ Test
652662 public void propertySourceAnnotation () {
653663 SpringApplication application = new SpringApplication (WithPropertySource .class );
You can’t perform that action at this time.
0 commit comments