zoukankan      html  css  js  c++  java
  • spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient

    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 {
    
    }
  • 相关阅读:
    phalcon——HTTP 请求
    phalcon——闪存消息
    phalcon——验证
    Java 字符串分隔 split
    Eclipse "R cannot be resolved"问题
    Android CountDownTimer 类实现倒计时
    Eclipse 打开时“发现了以元素'd:skin'”开头的无效内容。此处不应含有子元素
    Android Studio 设置/更改 SDK 路径
    Android 开发使用自定义字体
    Android Studio "ADB not responding"
  • 原文地址:https://www.cnblogs.com/handsome1013/p/10939382.html
Copyright © 2011-2022 走看看