From e2b4bea238a06a86291dc524992a5318be9dc010 Mon Sep 17 00:00:00 2001 From: Stefan Djurasic Date: Wed, 14 Jan 2015 12:31:58 +0100 Subject: [PATCH] Fixing copy/paste error in BootsrapApplicationListener ... which prevented using an external bootstrap.properties file Fixes gh-56, fixes gh-59 --- .../BootstrapApplicationListener.java | 2 +- .../external-properties/bootstrap.properties | 1 + .../BootstrapConfigurationTests.java | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-config-client/src/test/external-properties/bootstrap.properties diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java index 3fdca90d..9e906e61 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java @@ -92,7 +92,7 @@ public class BootstrapApplicationListener implements Map bootstrapMap = new HashMap<>(); bootstrapMap.put("spring.config.name", configName); if (StringUtils.hasText(configLocation)) { - bootstrapMap.put("spring.config.location", configName); + bootstrapMap.put("spring.config.location", configLocation); } bootstrapProperties.addFirst(new MapPropertySource( BOOTSTRAP_PROPERTY_SOURCE_NAME, bootstrapMap)); diff --git a/spring-cloud-config-client/src/test/external-properties/bootstrap.properties b/spring-cloud-config-client/src/test/external-properties/bootstrap.properties new file mode 100644 index 00000000..925265df --- /dev/null +++ b/spring-cloud-config-client/src/test/external-properties/bootstrap.properties @@ -0,0 +1 @@ +info.name: externalPropertiesInfoName \ No newline at end of file diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/BootstrapConfigurationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/BootstrapConfigurationTests.java index 495ded2b..7114afc6 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/BootstrapConfigurationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/BootstrapConfigurationTests.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; +import java.io.File; import java.util.Collections; import org.junit.After; @@ -56,6 +57,35 @@ public class BootstrapConfigurationTests { } } + @Test + public void pickupExternalBootstrapProperties() { + String externalPropertiesPath = getExternalProperties(); + + System.setProperty("spring.cloud.bootstrap.location", externalPropertiesPath); + context = new SpringApplicationBuilder().web(false) + .sources(BareConfiguration.class).run(); + assertEquals("externalPropertiesInfoName", context.getEnvironment().getProperty("info.name")); + assertTrue(context.getEnvironment().getPropertySources().contains("bootstrap")); + assertNotNull(context.getBean(ConfigClientProperties.class)); + } + + /** + * Running the test from maven will start from a different directory then starting it from intellij + * + * @return + */ + private String getExternalProperties() { + String externalPropertiesPath = ""; + File externalProperties = new File("src/test/external-properties/bootstrap.properties"); + if (externalProperties.exists()) { + externalPropertiesPath = externalProperties.getAbsolutePath(); + } else { + externalProperties = new File("spring-cloud-config-client/src/test/external-properties/bootstrap.properties"); + externalPropertiesPath = externalProperties.getAbsolutePath(); + } + return externalPropertiesPath; + } + @Test public void picksUpAdditionalPropertySource() { System.setProperty("expected.name", "bootstrap");