【Spring Cloud 系列】:构建Eureka Client 项目

一. 构建 Eureka Client 端

  1. 首先还是需要先看看官方文档是如何说明的,从文档中了解到,需要为项目引入Eureka-client 相关jar包

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

  2. 由于该服务是是web项目 所以还需要添加对应的web包。

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

    新建的Eureka Discovery 项目缺少web包,需要手动依赖。

    注意一点:就是使用的spring cloud版本不一样,这个web包有的版本可以缺省。

  Eureka Client项目启动报错:

    Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient':          org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

  出现以上错误,就是你的版本需要依赖web包

  3. 了解官方文档给的简单配置

  4. 这里有个心跳机制的新属性 leaseRenewalIntervalInSeconds , 官方文档的大概意思是:Eureka Client 默认 30秒会向 Server 端发送一次心跳,告诉 Server 端 我还活着~~~ ^_^  大哥~别杀我,作为我们的大哥 Server 端 默认是90秒对没有接收到 Client 端的续租请求将会举起屠刀。当然这些都是可以进行配置的.

感兴趣的可以研究一下:

 eureka.instance.leaseRenewalIntervalInSecondsz: 30

猜你喜欢

转载自blog.csdn.net/weixin_42740268/article/details/84824901