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 0cf0b0a8825..16e3e61784b 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 @@ -522,7 +522,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); @@ -588,7 +588,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, private Resource[] getResources(String location) { try { - if (location.contains("*")) { + if (isPatternLocation(location)) { return getResourcesFromPatternLocation(location); } return new Resource[] { this.resourceLoader.getResource(location) }; @@ -598,6 +598,10 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } } + private boolean isPatternLocation(String location) { + return location.contains("*"); + } + private Resource[] getResourcesFromPatternLocation(String location) throws IOException { String directoryPath = location.substring(0, location.indexOf("*/")); Resource resource = this.resourceLoader.getResource(directoryPath); 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 295242de5d7..229ffe3b683 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 @@ -1091,6 +1091,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/*/";