Spring Cloud Eureka Server使用(注册中心)

时间:2022-12-02 16:42:43

 一、Spring Cloud Eureka

基于Netflix Eureka做了二次封装

由两个组件组成

Eureka Server 注册中心, 供服务注册的服务器

Eureka Client 服务注册。 用于简化与服务器的交互

 

二、注册中心

Eureka Server

记录了所有应用的信息和状态

 

三、创建工程

Spring Cloud Eureka Server使用(注册中心)

下一步

Spring Cloud Eureka Server使用(注册中心)

下一步

Spring Cloud Eureka Server使用(注册中心)

 

然后在类EurekaApplication中增加EnableEurekaServer注解

Spring Cloud Eureka Server使用(注册中心)

 

创建好了之后,启动应用

但是不停的报如下错误

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

Spring Cloud Eureka Server使用(注册中心)

 解决方法:创建application.yml文件,增加如下图的配置

Spring Cloud Eureka Server使用(注册中心)

 

2、打开localhost:8080

Spring Cloud Eureka Server使用(注册中心)

 因为该应用程序是注册中心,不应该出现在Instances currently registered with Eureka中

所有增加配置

Spring Cloud Eureka Server使用(注册中心)

 

3、修改端口

因为Java很多默认的端口是8080,为了便于管理,将端口改成默认端口8761

Spring Cloud Eureka Server使用(注册中心)