@Autowired DiscoveryClient discoveryClient; /** * 根据gateway的service名字获得真实的URL * * @return */ public List<String> getAccountServiceUrl() { List<String> serviceUrls = discoveryClient.getInstances("account-service").stream() .map(a -> a.getUri().toString()) .collect(Collectors.toList()); return serviceUrls; } /** * 获取instance信息 * * @return */ public List<ServiceInstance> serviceUrl(String serviceName) { List<ServiceInstance> instances = discoveryClient.getInstances(serviceName); return instances; }