Eureka-动态获取路径
1、在启动类上添加@EnableDiscoveryClient注解
2、注入并调用方法
@Autowired
private DiscoveryClient discoveryClient;
List<ServiceInstance> instances = discoveryClient.getInstances("EUREKA-PROVIDER");
List<ServiceInstance> instances = discoveryClient.getInstances("EUREKA-PROVIDER");
if (instances.size()==0||instances==null){
return null;
}
ServiceInstance serviceInstance = instances.get(0);
String host = serviceInstance.getHost();//获取ip
int port = serviceInstance.getPort();//获取端口