springcloudeureka消费端

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 list = discoveryClient.getInstances("spring-data-demo");
    if (list != null && list.size() > 0 ) {
        return String.valueOf(list.get(0).getUri());
    }
    return null;
}

RestTemplate

@Configuration
public class RestTemplateConfiguration {
    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
@Autowired
private RestTemplate restTemplate;

@GetMapping("/restTemplateTest")
public String restTemplateTest(){
        String str = restTemplate.getForObject("http://data-demo/demo/hello", String.class);
        return str;
 }

网站栏目:springcloudeureka消费端
链接URL:http://myzitong.com/article/psgghh.html