日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient

發布時間:2025/3/15 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。