Commit b533ad3b by Dave Syer

Switch to spring.cloud.config.bootstrap.enabled=true

To enable EUreka-first bootstrap. See gh-42
parent 46e6d24a
...@@ -36,7 +36,7 @@ import com.netflix.discovery.DiscoveryClient; ...@@ -36,7 +36,7 @@ import com.netflix.discovery.DiscoveryClient;
* *
*/ */
@ConditionalOnClass({ DiscoveryClient.class, ConfigServicePropertySourceLocator.class }) @ConditionalOnClass({ DiscoveryClient.class, ConfigServicePropertySourceLocator.class })
@ConditionalOnExpression("${spring.cloud.bootstrap.useDiscovery:false}") @ConditionalOnExpression("${spring.cloud.config.discovery.enabled:false}")
@Configuration @Configuration
@EnableEurekaClient @EnableEurekaClient
@Import(EurekaClientAutoConfiguration.class) @Import(EurekaClientAutoConfiguration.class)
...@@ -44,8 +44,6 @@ import com.netflix.discovery.DiscoveryClient; ...@@ -44,8 +44,6 @@ import com.netflix.discovery.DiscoveryClient;
public class DiscoveryClientConfigServiceBootstrapConfiguration implements public class DiscoveryClientConfigServiceBootstrapConfiguration implements
ApplicationListener<ContextRefreshedEvent> { ApplicationListener<ContextRefreshedEvent> {
private static final String DEFAULT_CONFIG_SERVER = "CONFIGSERVER";
@Autowired @Autowired
private DiscoveryClient client; private DiscoveryClient client;
...@@ -56,7 +54,7 @@ public class DiscoveryClientConfigServiceBootstrapConfiguration implements ...@@ -56,7 +54,7 @@ public class DiscoveryClientConfigServiceBootstrapConfiguration implements
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
try { try {
log.info("Locating configserver via discovery"); log.info("Locating configserver via discovery");
InstanceInfo server = client.getNextServerFromEureka(DEFAULT_CONFIG_SERVER, InstanceInfo server = client.getNextServerFromEureka(delegate.getDiscovery().getServiceId(),
false); false);
String url = server.getHomePageUrl(); String url = server.getHomePageUrl();
if (server.getMetadata().containsKey("password")) { if (server.getMetadata().containsKey("password")) {
......
...@@ -62,7 +62,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests { ...@@ -62,7 +62,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
public void onWhenRequested() throws Exception { public void onWhenRequested() throws Exception {
Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn( Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn(
info); info);
setup("spring.cloud.bootstrap.useDiscovery=true"); setup("spring.cloud.config.discovery.enabled=true");
assertEquals( assertEquals(
1, 1,
context.getBeanNamesForType(DiscoveryClientConfigServiceBootstrapConfiguration.class).length); context.getBeanNamesForType(DiscoveryClientConfigServiceBootstrapConfiguration.class).length);
...@@ -77,7 +77,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests { ...@@ -77,7 +77,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
info.getMetadata().put("password", "bar"); info.getMetadata().put("password", "bar");
Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn( Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn(
info); info);
setup("spring.cloud.bootstrap.useDiscovery=true"); setup("spring.cloud.config.discovery.enabled=true");
ConfigServicePropertySourceLocator locator = context ConfigServicePropertySourceLocator locator = context
.getBean(ConfigServicePropertySourceLocator.class); .getBean(ConfigServicePropertySourceLocator.class);
assertEquals("http://foo:7001/", locator.getUri()); assertEquals("http://foo:7001/", locator.getUri());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment