日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eureka 服务注册与发现01——单机版

發布時間:2025/4/16 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eureka 服务注册与发现01——单机版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.





?



cloud-eureka-server7001 的pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>dym_cloud2021</artifactId><groupId>com.atguigu.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-eureka-server7001</artifactId><dependencies><!--eureka-server--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><!-- 引入自己定義的api通用包,可以使用Payment支付Entity --><dependency><groupId>com.atguigu.springcloud</groupId><artifactId>cloud-api-commons</artifactId><version>${project.version}</version></dependency><!--boot web actuator--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--一般通用配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId></dependency></dependencies></project>

application.yml

server:port: 7001eureka:instance:hostname: eureka7001.com #eureka服務端的實例名稱client:register-with-eureka: false #false表示不向注冊中心注冊自己。fetch-registry: false #false表示自己端就是注冊中心,我的職責就是維護服務實例,并不需要去檢索服務service-url:#集群指向其它eureka#defaultZone: http://eureka7002.com:7002/eureka/#單機就是7001自己# defaultZone: http://eureka7001.com:7001/eureka/defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/#server:#關閉自我保護機制,保證不可用服務被及時踢除#enable-self-preservation: false#eviction-interval-timer-in-ms: 2000

EurekaMain7001.java

package com.dym.springcloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication @EnableEurekaServer public class EurekaMain7001 {public static void main(String[] args) {SpringApplication.run(EurekaMain7001.class,args);} }



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

eureka:client:#表示是否將自己注冊進EurekaServer默認為true。register-with-eureka: true#是否從EurekaServer抓取已有的注冊信息,默認為true。單節點無所謂,集群必須設置為true才能配合ribbon使用負載均衡fetchRegistry: trueservice-url:#單機版defaultZone: http://localhost:7001/eureka# 集群版#defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eurekainstance:instance-id: payment8001#訪問路徑可以顯示IP地址prefer-ip-address: true#Eureka客戶端向服務端發送心跳的時間間隔,單位為秒(默認是30秒)#lease-renewal-interval-in-seconds: 1#Eureka服務端在收到最后一次心跳后等待時間上限,單位為秒(默認是90秒),超時將剔除服務#lease-expiration-duration-in-seconds: 2

?







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

application.yml

server:port: 80spring:application:name: cloud-order-serviceeureka:client:#表示是否將自己注冊進EurekaServer默認為true。register-with-eureka: true#是否從EurekaServer抓取已有的注冊信息,默認為true。單節點無所謂,集群必須設置為true才能配合ribbon使用負載均衡fetchRegistry: trueservice-url:#單機版defaultZone: http://localhost:7001/eureka


總結

以上是生活随笔為你收集整理的Eureka 服务注册与发现01——单机版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。