From 86ab7ef3dffcbb1f8a93b6917438f067521a2cdc Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 28 Jul 2014 08:46:21 -0700 Subject: [PATCH] Ensure profiles are used when fetching remote config --- .../ConfigServiceBootstrapConfiguration.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/spring-platform-config-client/src/main/java/org/springframework/platform/bootstrap/config/ConfigServiceBootstrapConfiguration.java b/spring-platform-config-client/src/main/java/org/springframework/platform/bootstrap/config/ConfigServiceBootstrapConfiguration.java index 01c65d9b..808e6a4d 100644 --- a/spring-platform-config-client/src/main/java/org/springframework/platform/bootstrap/config/ConfigServiceBootstrapConfiguration.java +++ b/spring-platform-config-client/src/main/java/org/springframework/platform/bootstrap/config/ConfigServiceBootstrapConfiguration.java @@ -30,10 +30,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.platform.config.client.ConfigServicePropertySourceLocator; import org.springframework.platform.config.client.PropertySourceLocator; +import org.springframework.util.StringUtils; /** * @author Dave Syer @@ -44,14 +46,16 @@ import org.springframework.platform.config.client.PropertySourceLocator; public class ConfigServiceBootstrapConfiguration implements ApplicationContextInitializer { - private static Log logger = LogFactory.getLog(ConfigServiceBootstrapConfiguration.class); + private static Log logger = LogFactory + .getLog(ConfigServiceBootstrapConfiguration.class); @Autowired(required = false) private List propertySourceLocators = new ArrayList(); - + public void setPropertySourceLocators( Collection propertySourceLocators) { - this.propertySourceLocators = new ArrayList(propertySourceLocators); + this.propertySourceLocators = new ArrayList( + propertySourceLocators); } @Override @@ -63,7 +67,8 @@ public class ConfigServiceBootstrapConfiguration implements PropertySource source = null; try { source = locator.locate(); - } catch (Exception e) { + } + catch (Exception e) { logger.error("Could not locate PropertySource: " + e.getMessage()); } if (source == null) { @@ -74,18 +79,24 @@ public class ConfigServiceBootstrapConfiguration implements empty = false; } if (!empty) { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment() + .getPropertySources(); if (propertySources.contains("bootstrap")) { propertySources.replace("bootstrap", composite); - } else { + } + else { propertySources.addFirst(composite); } } } @Bean - public ConfigServicePropertySourceLocator configServicePropertySource() { - return new ConfigServicePropertySourceLocator(); + public ConfigServicePropertySourceLocator configServicePropertySource( + ConfigurableEnvironment environment) { + ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(); + locator.setEnv(StringUtils.arrayToCommaDelimitedString(environment + .getActiveProfiles())); + return locator; } }