【Eureka篇三】Eureka服务发现(4)

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

修改子模块: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

猜你喜欢

转载自www.cnblogs.com/myitnews/p/11620525.html