Merge branch 'master' into 2.0.x

This commit is contained in:
Spencer Gibb
2017-10-23 21:10:28 -04:00
3 changed files with 33 additions and 5 deletions

View File

@@ -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;
}
}

View File

@@ -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<String> output = new LinkedHashSet<String>();
if (label == null) {
label = defaultLabel;
}
for (String location : locations) {
String[] profiles = new String[] { profile };
if (profile != null) {

View File

@@ -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"));
}
}