Skip to content

Commit 78e4b4c

Browse files
author
zongzhankui
committed
修改consul-consumer
1 parent 42473bd commit 78e4b4c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

2-Dalston版教程示例/consul-consumer/src/main/java/com/didispace/DcController.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.cloud.client.ServiceInstance;
5-
import org.springframework.cloud.client.discovery.DiscoveryClient;
6-
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
75
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
8-
import org.springframework.stereotype.Controller;
96
import org.springframework.web.bind.annotation.GetMapping;
107
import org.springframework.web.bind.annotation.RestController;
118
import org.springframework.web.client.RestTemplate;
@@ -25,7 +22,7 @@ public class DcController {
2522

2623
@GetMapping("/consumer")
2724
public String dc() {
28-
ServiceInstance serviceInstance = loadBalancerClient.choose("eureka-client");
25+
ServiceInstance serviceInstance = loadBalancerClient.choose("consul-client");
2926
String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/dc";
3027
System.out.println(url);
3128
return restTemplate.getForObject(url, String.class);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
spring.application.name=eureka-consumer
1+
spring.application.name=consul-consumer
22
server.port=2101
33

4-
eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/
4+
spring.cloud.consul.host=localhost
5+
spring.cloud.consul.port=8500
56

67
logging.file=${spring.application.name}.log

0 commit comments

Comments
 (0)