注:该知识点并不是重点。
修改子模块: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
原文地址:https://www.cnblogs.com/myitnews/p/11620525.html
时间: 2024-10-29 11:32:52