diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java index b74e6b56..88f92179 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java @@ -41,6 +41,7 @@ import org.springframework.web.client.RestTemplate; /** * @author Dave Syer * @author Ryan Baxter + * @author Daniel Lavoie * */ @Configuration @@ -109,10 +110,18 @@ class NativeRepositoryConfiguration { @Autowired private ConfigurableEnvironment environment; + + @Autowired + private ConfigServerProperties configServerProperties; @Bean public NativeEnvironmentRepository nativeEnvironmentRepository() { - return new NativeEnvironmentRepository(this.environment); + NativeEnvironmentRepository repository = new NativeEnvironmentRepository( + this.environment); + + repository.setDefaultLabel(configServerProperties.getDefaultLabel()); + + return repository; } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java index 870dc869..f8f7c22e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepository.java @@ -50,13 +50,15 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @author Roy Clarkson * @author Venil Noronha + * @author Daniel Lavoie */ @ConfigurationProperties("spring.cloud.config.server.native") -public class NativeEnvironmentRepository implements EnvironmentRepository, SearchPathLocator, Ordered { +public class NativeEnvironmentRepository + implements EnvironmentRepository, SearchPathLocator, Ordered { private static Log logger = LogFactory.getLog(NativeEnvironmentRepository.class); - - private static final String DEFAULT_LABEL = "master"; + + private String defaultLabel = "master"; /** * Locations to search for configuration files. Defaults to the same as a Spring Boot @@ -107,7 +109,11 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc } public String getDefaultLabel() { - return DEFAULT_LABEL; + return defaultLabel; + } + + public void setDefaultLabel(String defaultLabel) { + this.defaultLabel = defaultLabel; } @Override @@ -144,6 +150,10 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc locations = DEFAULT_LOCATIONS; } Collection output = new LinkedHashSet(); + + if (label == null) { + label = defaultLabel; + } for (String location : locations) { String[] profiles = new String[] { profile }; if (profile != null) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java index 8fe5d9ce..46a52efb 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java @@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext; * @author Dave Syer * @author Spencer Gibb * @author Venil Noronha + * @author Daniel Lavoie */ public class NativeEnvironmentRepositoryTests { @@ -41,6 +42,7 @@ public class NativeEnvironmentRepositoryTests { NativeEnvironmentRepositoryTests.class).web(WebApplicationType.NONE).run(); this.repository = new NativeEnvironmentRepository(context.getEnvironment()); this.repository.setVersion("myversion"); + this.repository.setDefaultLabel(null); context.close(); } @@ -188,5 +190,12 @@ public class NativeEnvironmentRepositoryTests { Locations locations = this.repository.getLocations("foo", "dev", null); assertEquals(1, locations.getLocations().length); } + + @Test + public void testDefaultLabel() { + this.repository.setDefaultLabel("test"); + assertEquals("test_bar", this.repository.findOne("foo", "default", null) + .getPropertySources().get(0).getSource().get("foo")); + } }