博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient
阅读量:6980 次
发布时间:2019-06-27

本文共 1524 字,大约阅读时间需要 5 分钟。

在使用服务发现的时候提到了两种注解,一种为@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.

意思也就是spring cloud中discovery service有许多种实现(eureka、consul、zookeeper等等),

@EnableDiscoveryClient基于spring-cloud-commons,
@EnableEurekaClient基于spring-cloud-netflix。

其实用更简单的话来说,

就是如果选用的注册中心是eureka,那么就推荐@EnableEurekaClient,
如果是其他的注册中心,那么推荐使用@EnableDiscoveryClient。

我们具体的对@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@Inheritedpublic @interface EnableEurekaClient {}

注解@EnableEurekaClient上有@EnableDiscoveryClient注解,

可以说基本就是EnableEurekaClient有@EnableDiscoveryClient的功能,
另外上面的注释中提到,其实@EnableEurekaClient注解就是一种方便使用eureka的注解而已,
可以说使用其他的注册中心后,都可以使用@EnableDiscoveryClient注解,
但是使用@EnableEurekaClient的情景,就是在服务采用eureka作为注册中心的时候,使用场景较为单一。

转载地址:http://rqjpl.baihongyu.com/

你可能感兴趣的文章
快速生成CSS--LESS学习总结
查看>>
ubuntu安装Jetty
查看>>
jqgrid合并单元格
查看>>
纯C实现jsonrpc
查看>>
使用tomcat 7的 maven插件启动项目
查看>>
spring task执行两次解决办法(修改tomcat配置)
查看>>
android 4.4(KitKat)上,如何开发SMS功能的APP
查看>>
转】Javascript 中的false,零值,null,undefined和空字符串对象
查看>>
Nodejs使用fs判断文件是否存在
查看>>
spring中bean配置和bean注入
查看>>
关于proguard,你需要知道的全部
查看>>
百度 Ueditor 编辑器学习笔记
查看>>
Tomcat reloadable属性 让你修改Java代码不必自动重启服务器
查看>>
PHPUnit 单元测试入门笔记
查看>>
Oracle - install
查看>>
你真的会用Gson吗?Gson使用指南(一)
查看>>
tomcat单机多实例配置实战
查看>>
onSaveInstanceState用法
查看>>
BeanFactory 简介以及它 和FactoryBean的区别
查看>>
为什么重写equals方法时,要求必须重写hashCode方法?
查看>>