Eureka篇三Eureka服务发现

Posted myitnews

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Eureka篇三Eureka服务发现相关的知识,希望对你有一定的参考价值。

注:该知识点并不是重点。

修改子模块:microservicecloud-provider-dept-8001

1. 修改DeptController

@Autowired
private org.springframework.cloud.client.discovery.DiscoveryClient client;

@RequestMapping(value = "/discovery", method = RequestMethod.GET)
public Object discovery()
    List<String> services = client.getServices();
    System.out.println("services list = " + services);
    
    List<ServiceInstance> instances = client.getInstances("microservicecloud-dept".toUpperCase());
    for(ServiceInstance ins : instances)
        System.out.println(ins.getServiceId()+"\t"+ins.getHost()+"\t"+ins.getPort()+"\t"+ins.getUri());
    
    return client;

2. 启动类添加服务发现注解@EnableDiscoveryClient

3. 启动项目,访问http://localhost:8001/dept/discovery

 

以上是关于Eureka篇三Eureka服务发现的主要内容,如果未能解决你的问题,请参考以下文章