spring cloud服务发现注解之@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**z注解就是一种方便使用eureka的注解而已,可以说使用其他的注册中心后,都可以使用@EnableDiscoveryClient注解,但是使用@EnableEurekaClient的情景,就是在服务采用eureka作为注册中心的时候,使用场景较为单一。