From 81058cab030ba98e221ce8046c50c43411219c61 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 7 May 2020 07:56:01 -0700 Subject: [PATCH] Allow clash in spring.config.name Remove the recently added slash restriction since Spring Cloud Config Server needs to support names with slashes. See gh-21217 --- .../context/config/ConfigFileApplicationListener.java | 2 -- .../config/ConfigFileApplicationListenerTests.java | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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 05880791fd..c052425c0a 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 @@ -728,8 +728,6 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, private void assertValidConfigName(String name) { Assert.state(!name.contains("*"), () -> "Config name '" + name + "' cannot contain wildcards"); - Assert.state(!name.contains("/") && !name.contains("\\"), - () -> "Config name '" + name + "' cannot contain slashes"); } private void addLoadedPropertySources() { 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 b6aa1d1077..a9884fdca9 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 @@ -1051,6 +1051,14 @@ class ConfigFileApplicationListenerTests { .withMessage("Config name '*/application' cannot contain wildcards"); } + @Test + void configNameCanContainSlash() { + // Spring Cloud config server depends on this + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, + "spring.config.location=file:src/test/resources/", "spring.config.name=config/application"); + this.initializer.postProcessEnvironment(this.environment, this.application); + } + @Test void directoryLocationsWithMultipleWildcardsShouldThrowException() { String location = "file:src/test/resources/config/**/";