码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud eureka 消费端

时间:2018-05-20 15:23:34      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:eureka

EurekaClient

@Qualifier("eurekaClient")
@Autowired
private EurekaClient eurekaClient;

public String dataServiceUrlByEurekaClient() {
    InstanceInfo instance = eurekaClient.getNextServerFromEureka("spring-data-demo", false);
    return instance.getHomePageUrl();
}

DiscoveryClient

@Autowired
private DiscoveryClient discoveryClient;
public String dataServiceUrlByDiscoveryClient() {
    List<ServiceInstance> list = discoveryClient.getInstances("spring-data-demo");
    if (list != null && list.size() > 0 ) {
        return String.valueOf(list.get(0).getUri());
    }
    return null;
}

spring cloud eureka 消费端

标签:eureka

原文地址:http://blog.51cto.com/881206524/2118415

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!