• springcloud注解@EnableDiscoveryClient与@EnableEurekaC


    spring cloud中discovery service有许多种实现(eureka、consul、zookeeper等等),@EnableDiscoveryClient基于spring-cloud-commons, @EnableEurekaClient基于spring-cloud-netflix。

    其实用更简单的话来说,就是如果选用的注册中心是eureka,那么就推荐@EnableEurekaClient,如果是其他的注册中心,那么推荐使用@EnableDiscoveryClient。

    @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 {
    }

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

  • 相关阅读:
    alipay h5支付接口总结
    ztree js 和父子节点递归 使用注意
    .net framework to mono 绿色运行摘记
    curl 命令行用法摘记
    C# Camera2 实现扫描识别二维码及Texture预览
    .net framework 3.5 安装命令
    android 调用相机
    Xamarin Android 定时刷新UI
    Xamarin 动态申请 android 权限
    C# 生成和识别二维码
  • 原文地址:https://www.cnblogs.com/xyhero/p/e71cecf43df899a3b348480b2629497f.html
Copyright © 2020-2023  润新知