spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient
使用服務發現的時候提到了兩種注解,一種為@EnableDiscoveryClient,一種為@EnableEurekaClient,用法上基本一致,今天就來講下兩者,下文是從stackoverflow上面找到的對這兩者的解釋:
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.
?
原文地址為:What’s the difference between EnableEurekaClient and EnableDiscoveryClient?
意思也就是spring cloud中discovery service有許多種實現(eureka、consul、zookeeper等等),@EnableDiscoveryClient基于spring-cloud-commons, @EnableEurekaClient基于spring-cloud-netflix。
其實用更簡單的話來說,就是如果選用的注冊中心是eureka,那么就推薦@EnableEurekaClient,如果是其他的注冊中心,那么推薦使用@EnableDiscoveryClient。
?
注解@EnableEurekaClient上有@EnableDiscoveryClient注解,可以說基本就是EnableEurekaClient有@EnableDiscoveryClient的功能,
另外上面的注釋中提到,其實**@EnableEurekaClient**z注解就是一種方便使用eureka的注解而已,可以說使用其他的注冊中心后,
都可以使用@EnableDiscoveryClient注解,但是使用@EnableEurekaClient的情景,就是在服務采用eureka作為注冊中心的時候,使用場景較為單一。
@EnableEurekaClient
我們具體的對@EnableEurekaClient的源碼看一下,如下:
/*** Convenience annotation for clients to enable Eureka discovery configuration* (specifically). Use this (optionally) in case you want discovery and know for sure that* it is Eureka you want. All it does is turn on discovery and let the autoconfiguration* find the eureka classes if they are available (i.e. you need Eureka on the classpath as* well).** @author Dave Syer* @author Spencer Gibb*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @EnableDiscoveryClient public @interface EnableEurekaClient {}總結
以上是生活随笔為你收集整理的spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tablespace innodb_in
- 下一篇: js模板引擎art template数组