了解 单机Eureka构建流程,以及服务注册功能实现
<!-- 服务注册中心的服务端 eureka-server -->
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
server:
port: 7001
# 单机版本
eureka:
instance:
hostname: localhost # eureka 服务端的实例名称
client:
register-with-eureka: false # 表示不向注册中心注册自己
fetch-registry: false # 表示自己就是注册中心,职责是维护服务实例,并不需要去探索服务
service-url:
# 设置与 eureka server 交互的地址查询服务和注册服务都需要依赖这个地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
EnableEurekaServer注解@EnableEurekaServer //设置为服务注册中心 EurekaServer
此时还没有实例注册进来
服务注册中心的客户端 eureka-client <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
eureka:
client:
register-with-eureka: true #是否向注册中心注册自己 默认为 true
#是否从注册中心抓取已有的注册信息 默认true,单节点无所谓,集群必须设置为 true 才能配合ribbon使用负载均衡
fetchRegistry: true
service-url:
# 设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址
defaultZone: http://localhost:7001/eureka #单机版
Eureka中 (启动类加注解)@EnableEurekaClient
运行 两个模块,结果如下
步骤和第五点相同,下面直接展示结果

