Fixing copy/paste error in BootsrapApplicationListener
... which prevented using an external bootstrap.properties file Fixes gh-56, fixes gh-59
This commit is contained in:
committed by
Dave Syer
parent
3796133980
commit
e2b4bea238
@@ -92,7 +92,7 @@ public class BootstrapApplicationListener implements
|
||||
Map<String, Object> 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));
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
info.name: externalPropertiesInfoName
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user