外贸网站打开速度,wordpress路由重写,天津卓荣建设集团网站,俄语企业网站制作定义#xff1a;EnableEurekaServer注解是Spring Cloud中的一个注解#xff0c;用于将Spring Boot应用程序指定为Eureka服务器。
Eureka服务器是一个服务注册中心#xff0c;也被称为发现服务器#xff0c;管理和协调微服务。保存有关所有客户端服务应用程序的信息。
每个…定义EnableEurekaServer注解是Spring Cloud中的一个注解用于将Spring Boot应用程序指定为Eureka服务器。
Eureka服务器是一个服务注册中心也被称为发现服务器管理和协调微服务。保存有关所有客户端服务应用程序的信息。
每个微服务都会注册到Eureka服务器然后Eureka服务器就知道每个端口和IP地址上运行的所有客户端应用程序。
使用 在Spring Boot应用程序的主类(启动类)中添加EnableEurekaServer注解就可以启动一个Eureka服务器。默认端口号8761
注解的源代码
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//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.context.annotation.Import;Target({ElementType.TYPE})
Retention(RetentionPolicy.RUNTIME)
Documented
Import({EurekaServerMarkerConfiguration.class})
public interface EnableEurekaServer {
}
EurekaServerMarkerConfiguration.class源码
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package org.springframework.cloud.netflix.eureka.server;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration(proxyBeanMethods false
)
public class EurekaServerMarkerConfiguration {public EurekaServerMarkerConfiguration() {}Beanpublic EurekaServerMarkerConfiguration.Marker eurekaServerMarkerBean() {return new EurekaServerMarkerConfiguration.Marker();}class Marker {Marker() {}}
}
源码分析 1.EnableEurekaServer 注解直接导入了配置类EurekaServerMarkerConfiguration,而这个配置类中向spring容器中注册了一个EurekaServerMarkerConfiguration的Bean。 这个注解可以看作是一个开关开启时会激活相关配置去作为注册中心。
2.EurekaServerMarkerConfiguration配置类中向容器中注入了一个类EurekaServerMarkerConfiguration.Marker用来激活配置类。
总结在Spring Cloud中当你需要使用Eureka注册中心的时候需要在Eureka的服务端启动类上添加EnableEurekaServer注解 【用于激活Eureka服务器相关配置将项目作为Spring Cloud中的注册中心让Eureka服务器能正常运行提供服务发现的功能】