【Eureka】服务注册到eureka / eureka-client 配置

EUREKA客户端怎样配置

相关版本

springboot 版本:2.1.17 (貌似 springboot1.x 和 2.x 有一点区别)

步骤

1、添加依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

2、启动类添加注解

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
public class MyApplication {
    // balabala 启动类
}

3、配置中心/配置文件 添加 eureka-client 信息

eureka:
  client:
    registryFetchIntervalSeconds: 5
    instanceInfoReplicationIntervalSeconds: 5
    initialInstanceInfoReplicationIntervalSeconds: 5
    serviceUrl:
       defaultZone: http://@localhost:8761/eureka/
       #defaultZone: http://username:password@localhost:8761/eureka/   (如果设置了账号密码,就用这种写法)

至此,eureka-client 端的配置就基本完成了。。。

posted @ 2022-05-23 21:11  aaacarrot  阅读(32)  评论(0编辑  收藏  举报