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 a982d7a95541..e583445b9063 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 @@ -507,7 +507,7 @@ private void load(PropertySourceLoader loader, String location, Profile profile, } 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 @@ private String getLocationName(String locationReference, Resource resource) { 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 @@ private Resource[] getResources(String locationReference) { } } + 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); 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 92971ad2f065..f0ffcc0dc6b3 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 @@ -1086,6 +1086,16 @@ void locationsWithWildcardDirectoriesShouldIgnoreHiddenDirectories() { 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/*/";