当前位置: 首页 > news >正文

@EnableEurekaServer

定义:@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服务器能正常运行,提供服务发现的功能】

http://www.lryc.cn/news/287823.html

相关文章:

  • Java中的接口
  • Linux笔记之bash脚本中的-e、和
  • mapstruct自定义转换,怎样将String转化为List
  • torch.matmul和torch.bmm区别
  • k8s学习(RKE+k8s+rancher2.x)成长系列之概念介绍(一)
  • PHP - Yii2 异步队列
  • leetcode560和为k的子数组
  • 【ProtoBuf】使用指南
  • Buffer Pool
  • jetson-inference----docker内运行分类任务
  • Python脚本之操作Redis Cluster【二】
  • 认识数学建模
  • 计算机工作原理解析和解剖(基础版)
  • 外网ssh远程连接服务器
  • 滴滴基于 Ray 的 XGBoost 大规模分布式训练实践
  • k8s从入门到实践
  • Qt5.12.0 与 VS2017 在 .pro文件转.vcxproj文件
  • 金蝶云星空 ServiceGateway RCE漏洞复现
  • 二叉树的最大深度[简单]
  • [Redis]不同系统间安装redis服务器
  • Unity之动画和角色控制
  • C语言库函数实现字符串转大小写
  • hcip----ospf
  • vue中如何写过滤器
  • c语言-文件的读写操作(下)
  • android学习笔记----SQLite数据库
  • 开发知识点-Flutter移动应用开发
  • 视频尺寸魔方:分层遮掩3D扩散模型在视频尺寸延展的应用
  • openssl3.2/test/certs - 061 - other@good.org not permitted by CA1
  • 如何实现无公网ip远程访问本地websocket服务端【内网穿透】