> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/spring-cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/spring-cloud/fu-wu-de-zhu-ce-yu-fa-xian/qi-ta-zhi-shi/discoveryclient-yu-enableeurekaserver.md).

# DiscoveryClient 与@EnableEurekaServer

## DiscoveryClient用法&#x20;

discoveryClient接口 可以获取注册中心上的实例信息。

&#x20;@EnableDiscoveryClient 开启其他注册中心 比如consul、zookeeper

```java
@SpringBootApplication
@EnableDiscoveryClient
public class AppMember {
	public static void main(String[] args) {
		SpringApplication.run(AppMember.class, args);
	}
}
```

获取注册中心上信息

```java
@RequestMapping("/getServiceUrl")
	public List<String> getServiceUrl() {
		List<ServiceInstance> list = discoveryClient.getInstances("zk-member");
		List<String> services = new ArrayList<>();
		for (ServiceInstance serviceInstance : list) {
			if (serviceInstance != null) {
				services.add(serviceInstance.getUri().toString());
			}
		}
		return services;
	}
```

## @EnableDiscoveryClient 与@EnableEurekaClient区别

1，@EnableDiscoveryClient注解是基于spring-cloud-commons依赖，并且在classpath中实现； 适合于consul、zookeeper注册中心&#x20;

2，@EnableEurekaClient注解是基于spring-cloud-netflix依赖，只能为eureka作用；
