springcloud 之服务注册与发现 Eureka Client
生活随笔
收集整理的這篇文章主要介紹了
springcloud 之服务注册与发现 Eureka Client
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在上一篇文章中我們已經成功的搭建了一個基于springcloud eureka的服務發現與注冊中心,但是我們并沒有向其中注入任何服務實例,接下來我將教大家如何將現有的服務注冊到我們自己的eureka注冊中心。
注:基于demo-springboot
1.打開pom.xml加入相關依賴:
<!--eureka client--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.0.RELEASE</version> </dependency>2.打開application-dev.properties并加入以下內容:
#實例名 spring.application.name=demo-springboot #注冊中心 eureka.server.host=localhost eureka.server.port=8761 eureka.client.service-url.defaultZone=http://${eureka.server.host}:${eureka.server.port}/eureka/ #feign read timeout(10s) hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000 #feign read timout disable #hystrix.command.default.execution.timeout.enabled=false #開啟eureka client健康檢查 eureka.client.healthcheck=true # 續約到期時間(默認90秒) eureka.instance.lease-expiration-duration-in-seconds=30 # 續約更新時間間隔(默認30秒) eureka.instance.lease-renewal-interval-in-seconds=103.打開啟動類加入相應注解@EnableEurekaClient:
@EnableEurekaClient @EnableAutoConfiguration @MapperScan({"com.example.demo.dao"}) @SpringBootApplication public class DemoSpringbootApplication {public static void main(String[] args) {SpringApplication.run(DemoSpringbootApplication.class, args); } }右鍵run application,
瀏覽器查看我們的服務已經注冊進去了。
注:如果我們想對同一個服務注冊多個實例呢?(即服務實例集群),我們只需要復制一份項目修改一下端口重新打包發布即可,相信看到這里有的童鞋已經明白了我的意圖:為以后的分布式服務做鋪墊。
總結
以上是生活随笔為你收集整理的springcloud 之服务注册与发现 Eureka Client的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 片仔癀大跌原因,业绩不及预期
- 下一篇: springcloud 之 路由网关 z