微服务之SpringCloud实战(四):SpringCloud Eureka源码分析
2018-11-14 17:53
956 查看
Eureka源码解析:
搭建Eureka服务的时候,我们会再SpringBoot启动类加上@EnableEurekaServer的注解,这个注解做了一些什么,我们一起来看。
点进@EnableEurekaServer这个注解就会看到下面代码:
/* * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.cloud.netflix.eureka.server; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.annotation.Import; /** * Annotation to activate Eureka Server related configuration {@link EurekaServerAutoConfiguration} * * @author Dave Syer * @author Biju Kunjummen * */ @EnableDiscoveryClient @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Import(EurekaServerMarkerConfiguration.class) public @interface EnableEurekaServer { }
大家可以清楚的看到@EnableEurekaServer引用了@EnableDiscoveryClient这个注解,源码如下:
/* * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.cloud.client.discovery; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Import; /** * Annotation to enable a DiscoveryClient implementation. * @author Spencer Gibb */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Import(EnableDiscoveryClientImportSelector.class) public @interface EnableDiscoveryClient { /** * If true, the ServiceRegistry will automatically register the local server. */ boolean autoRegister() default true; }
从这个注解我们可以知道,它主要是用来开启DiscoveryClient实例的,通过搜索DiscoveryClient我们可以看到一个类和一个接口,得到下图关系:
待补充................
相关文章推荐
- SpringCloud组件 & 源码剖析:Eureka服务注册方式流程全面分析
- Spring Cloud分布式微服务云架构源码分析 — Eureka
- SpringCloud微服务实战---服务的注册和发现(Eureka)
- spring cloud服务发现和注册源码分析
- Spring Cloud Netflix Eureka client源码分析
- SpringCloud——服务注册与发现Eureka以及注册源码解析
- spring cloud zuul网关服务重试请求配置和源码分析
- SpringCloud系列:Eureka源码分析(二)
- spring-cloud-eureka (二) Client - Server 接口交互(消息发送)源码分析
- spring-cloud-eureka (三) 注册中心源码分析
- Spring-cloud & Netflix 源码解析:Eureka 服务注册发现接口 ****
- Spring-cloud & Netflix 源码解析:Eureka 服务注册发现接口 ****
- springcloud微服务实战:Eureka+Zuul+Feign/Ribbon+Hystrix Turbine+SpringConfig+sleuth+zipkin
- springcloud实战之3 高可用服务注册中心(eureka集群)
- Spring Cloud源码分析(一)Eureka