Commit 6fe30a8a authored by Phillip Webb's avatar Phillip Webb

Merge branch '2.2.x'

Closes gh-21175
parents 2bfba4a1 36b082e8
......@@ -63,6 +63,7 @@ import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
......@@ -656,6 +657,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;
}
......
......@@ -710,6 +710,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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment