Browse Source

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

To enable EUreka-first bootstrap.

See gh-42
pull/6/head
Dave Syer 10 years ago
parent
commit
b533ad3bb2
  1. 6
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfiguration.java
  2. 4
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java

6
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfiguration.java

@ -36,7 +36,7 @@ import com.netflix.discovery.DiscoveryClient; @@ -36,7 +36,7 @@ import com.netflix.discovery.DiscoveryClient;
*
*/
@ConditionalOnClass({ DiscoveryClient.class, ConfigServicePropertySourceLocator.class })
@ConditionalOnExpression("${spring.cloud.bootstrap.useDiscovery:false}")
@ConditionalOnExpression("${spring.cloud.config.discovery.enabled:false}")
@Configuration
@EnableEurekaClient
@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
ApplicationListener<ContextRefreshedEvent> {
private static final String DEFAULT_CONFIG_SERVER = "CONFIGSERVER";
@Autowired
private DiscoveryClient client;
@ -56,7 +54,7 @@ public class DiscoveryClientConfigServiceBootstrapConfiguration implements @@ -56,7 +54,7 @@ public class DiscoveryClientConfigServiceBootstrapConfiguration implements
public void onApplicationEvent(ContextRefreshedEvent event) {
try {
log.info("Locating configserver via discovery");
InstanceInfo server = client.getNextServerFromEureka(DEFAULT_CONFIG_SERVER,
InstanceInfo server = client.getNextServerFromEureka(delegate.getDiscovery().getServiceId(),
false);
String url = server.getHomePageUrl();
if (server.getMetadata().containsKey("password")) {

4
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java

@ -62,7 +62,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests { @@ -62,7 +62,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
public void onWhenRequested() throws Exception {
Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn(
info);
setup("spring.cloud.bootstrap.useDiscovery=true");
setup("spring.cloud.config.discovery.enabled=true");
assertEquals(
1,
context.getBeanNamesForType(DiscoveryClientConfigServiceBootstrapConfiguration.class).length);
@ -77,7 +77,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests { @@ -77,7 +77,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
info.getMetadata().put("password", "bar");
Mockito.when(client.getNextServerFromEureka("CONFIGSERVER", false)).thenReturn(
info);
setup("spring.cloud.bootstrap.useDiscovery=true");
setup("spring.cloud.config.discovery.enabled=true");
ConfigServicePropertySourceLocator locator = context
.getBean(ConfigServicePropertySourceLocator.class);
assertEquals("http://foo:7001/", locator.getUri());

Loading…
Cancel
Save