140

In some applications, I saw people are using @EnableEurekaClient. And some other example applications are using @EnableDiscoveryClient.

Is there any difference between these two?

ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30
YongJiang Zhang
  • 1,989
  • 2
  • 20
  • 25

5 Answers5

238

There are multiple implementations of "Discovery Service" (eureka, consul, zookeeper). @EnableDiscoveryClient lives in spring-cloud-commons and picks the implementation on the classpath. @EnableEurekaClient lives in spring-cloud-netflix and only works for eureka. If eureka is on your classpath, they are effectively the same.

spencergibb
  • 24,471
  • 6
  • 69
  • 75
  • 1
    Question : Will both of above mentioned annotations enable Ribbon-enabled interceptor injected into RestTemplate? Any difference in behavior? I noticed that in previous Spring Cloud implementations `@LoadBalanced` was automatically applied, but in current version, it is required explicitly. Thank you. – fg78nc Jun 24 '18 at 22:48
  • 1
    Yes. There is no difference. The load balanced annotation has been required for a long time. – spencergibb Jun 25 '18 at 02:43
  • 5
    Why would someone want to use @EnableEurekaClient over the more general @EnableDisocveryClient? Wouldn't that bind them to the eureka implementation and make it harder to switch SD backends in the future? – Adam Hughes Jan 09 '19 at 18:20
  • 5
    Yes. The only answer is if they want to be clear and enforce eureka. – spencergibb Jan 09 '19 at 21:03
7

Discovery service concept in spring cloud is implemented in different ways like Eureka, consul, zookeeper etc. If you are using Eureka by Netflix then @EnableEurekaClient is specifically for that. But if you are using any other service discovery including Eureka you can use @EnableDiscoveryClient.

Chinmay Biswal
  • 303
  • 5
  • 9
3

In terms of its practicality and simplicity, if the registered center is eureka, then @EnableEurekaClient is recommended. If it is another registration center, @EnableDiscoveryClient is recommended.

Mohamed Hassona
  • 308
  • 4
  • 16
3

@EnableEurekaCient will initilize the service discovery using eureka server, its like explicitly specifying to use EUREKA

While @EnableDiscovery Client will register dicovery service using the jar available in classpath like consul, Eureka, Kubernetes.

Vrubal
  • 61
  • 2
1

@EnableEurekaClient works only for Eureka if we use @EnableDiscoveryClient we can use any discovery client like Consul other than Eureka