Merge branch '2.3.x'

See gh-24043
This commit is contained in:
Andy Wilkinson
2020-11-11 15:39:23 +00:00
2 changed files with 16 additions and 2 deletions

View File

@@ -507,7 +507,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
continue;
}
if (resource.isFile() && hasHiddenPathElement(resource)) {
if (resource.isFile() && isPatternLocation(location) && hasHiddenPathElement(resource)) {
if (this.logger.isTraceEnabled()) {
StringBuilder description = getDescription("Skipped location with hidden path element ",
location, resource, profile);
@@ -573,7 +573,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
private Resource[] getResources(String locationReference) {
try {
if (locationReference.contains("*")) {
if (isPatternLocation(locationReference)) {
return getResourcesFromPatternLocationReference(locationReference);
}
return new Resource[] { this.resourceLoader.getResource(locationReference) };
@@ -583,6 +583,10 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
}
private boolean isPatternLocation(String location) {
return location.contains("*");
}
private Resource[] getResourcesFromPatternLocationReference(String locationReference) throws IOException {
String directoryPath = locationReference.substring(0, locationReference.indexOf("*/"));
Resource resource = this.resourceLoader.getResource(directoryPath);

View File

@@ -1086,6 +1086,16 @@ class ConfigFileApplicationListenerTests {
assertThat(this.environment.getProperty("fourth.property")).isNull();
}
@Test
void nonWildcardHiddenDirectoryLocationShouldNotBeIgnored() {
String location = "file:src/test/resources/config/..hidden/";
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
"spring.config.location=" + location);
this.initializer.setSearchNames("testproperties");
this.initializer.postProcessEnvironment(this.environment, this.application);
assertThat(this.environment.getProperty("fourth.property")).isNotNull();
}
@Test
void locationsWithWildcardDirectoriesShouldLoadAllFilesThatMatch() {
String location = "file:src/test/resources/config/*/";