springboot+eureka(分布式注册中心)实现服务注册与发现

本文章简单介绍如何实现服务注册与发现

1.eureka server

 添加所需依赖
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

2.配置server

# 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己
eureka.client.fetch-registry=false
# 由于注册中心的职责就是维护服务实例,他并不需要去检索服务,所以也设置为false
eureka.client.register-with-eureka=false
eureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.instance.hostname=localhost
#配置属性,但由于 Eureka 自我保护模式以及心跳周期长的原因,经常会遇到 Eureka Server 不剔除已关停的节点的问题
# 关闭自我保护
eureka.server.enable-self-preservation=false
#清理间隔(单位毫秒,默认是60*1000)
eureka.server.eviction-interval-timer-in-ms=5000

3.集成security

#启用身份认证
security.basic.enabled=true
#自定义用户名,密码
security.user.name=snjx
security.user.password=snjx
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-security</artifactId>
</dependency>

4.添加注解


5.eureka client使用

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


6.访问地址

http://localhost:8761/eureka/


  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值