SpringCloud(1)-配置eureka服務註冊中心

eureka服務註冊中心

springcloud的介紹

springCloud主要是一款用於分佈式開發的框架,它集成了服務註冊中心,服務,路由,網關,監控,配置中心,斷路器等功能。我們可以使用SpringCloud來開發我們的分佈式系統。

eureka服務註冊中心

  1. 我們先創建一個springboot工程,在pom.xml文件中加入以下依賴

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    
  2. 同時我們需要在application.properties如下配置

    #指定服務的端口
    server.port=82 
    #指定該應用的名稱
    spring.application.name=eureka-server
    #指定服務註冊中心的地址
    eureka.instance.hostname=localhost
    #指定服務註冊中心的訪問路徑,所有的客戶端,消費者都需要在這裏註冊
    eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka-server/  
    #指定是否客戶端註冊
    eureka.client.fetch-registry=false 
    #指定是否註冊到eureka服務註冊中心
    eureka.client.register-with-eureka=false
    
  3. 在springBoot的啓動類上添加@EnableEurekaServer的註解,然後啓動該應用
  4. 啓動完成後,我們根據地址以及端口號訪問該項目,本例就直接訪問http://localhost:82,效果圖如下這裏寫圖片描述
  5. 在這裏我們可以查看註冊到該服務註冊中心的服務
    這裏寫圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章