From f918a46ea2715acecf8ec844d7dab18a75e89af0 Mon Sep 17 00:00:00 2001 From: mederel Date: Mon, 14 Dec 2020 13:28:59 +0100 Subject: [PATCH] Support system-dependent path separators Update `StandardConfigDataLocationResolver` so that it recognizes both `/` and `File.separator` suffixes as directories. Prior to this commit, working with directories on Windows was awkward since the path separator is `\`. If a directory were specified in the form `c:\config\`, an exception was raised complaining it did not end with '/'. See gh-24490 --- .../context/config/StandardConfigDataLocationResolver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java index f21970c391..c6ca85e671 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.io.File; import org.apache.commons.logging.Log; @@ -212,7 +213,7 @@ public class StandardConfigDataLocationResolver } } throw new IllegalStateException("File extension is not known to any PropertySourceLoader. " - + "If the location is meant to reference a directory, it must end in '/'"); + + "If the location is meant to reference a directory, it must end in '/' or File.separator"); } private String getLoadableFileExtension(PropertySourceLoader loader, String file) { @@ -225,7 +226,7 @@ public class StandardConfigDataLocationResolver } private boolean isDirectory(String resourceLocation) { - return resourceLocation.endsWith("/"); + return resourceLocation.endsWith("/") || resourceLocation.endsWith(File.separator); } private List resolve(Set references) {