内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

springcloudconfig整合gitlab如何搭建分布式的配置中心

本文小編為大家詳細(xì)介紹“spring cloud config整合gitlab如何搭建分布式的配置中心”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“spring cloud config整合gitlab如何搭建分布式的配置中心”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。

創(chuàng)新互聯(lián)專(zhuān)業(yè)為企業(yè)提供邳州網(wǎng)站建設(shè)、邳州做網(wǎng)站、邳州網(wǎng)站設(shè)計(jì)、邳州網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、邳州企業(yè)網(wǎng)站模板建站服務(wù),十年邳州做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

前提:在gitlab中的工程下新建一個(gè)配置文件configserver-dev.properties

一、配置Server

1、添加依賴(lài)

<dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-config-server</artifactId> 
    </dependency>

2、在Application主類(lèi)開(kāi)啟支持

@EnableConfigServer

3、配置application.yml文件

server: 
 port: 8888 
spring: 
 application: 
  name: config 
 cloud: 
  config: 
   server: 
    git: 
     uri: https://gitlab.xxx.com/xxxxx/xxxxx.git   # 配置gitlab倉(cāng)庫(kù)的地址,注意,此處必須以.git結(jié)尾 
     search-paths: /config-repo # gitlab倉(cāng)庫(kù)地址下的相對(duì)地址,可以配置多個(gè),用,分割。 
     username: your username                       # gitlab倉(cāng)庫(kù)的賬號(hào) 
     password: your password                       # gitlab倉(cāng)庫(kù)的密碼

注意:如果配置文件放置在Git存儲(chǔ)庫(kù)的根目錄下,則無(wú)需使用searchPaths參數(shù),本例中的配置文件在config-repo目錄中,因此使用searchPaths參數(shù)提示Config服務(wù)器搜索config-repo子目錄

4、啟動(dòng)server,并在瀏覽器輸入http://localhost:8888/configserver/dev/master

{ 
 
  "name": "configserver", 
  "profiles": [ 
    "dev" 
  ], 
  "label": "master", 
  "version": "073cda9ce85a3eed00e406f4ebcc4651ee4d9b19", 
  "state": null, 
  "propertySources": [ 
    { 
      "name": "https://gitlab.xxx.com/xxxxx/xxxxx/project/config-repo/configserver.properties", 
      "source": { 
        "name": "chhliuxyh", 
        "hello": "i'm the king of the world!!!", 
        "profile": "profile-default" 
      } 
    } 
  ] 
 
}

可以看到server端已經(jīng)可以從gitlab上讀取到配置文件了??梢酝ㄟ^(guò)如下表單中的方式訪問(wèn)gitlab上的資源

/{application}/{profile}[/{label}] 
/{application}-{profile}.yml 
/{label}/{application}-{profile}.yml 
/{application}-{profile}.properties 
/{label}/{application}-{profile}.properties

例如在瀏覽器中輸入:http://localhost:8888/configserver-dev.yml,結(jié)果如下:

hello: i'm the king of the world!!! 
name: chhliuxyh 
profile: profile-default

二、配置客戶端

1、添加pom依賴(lài)

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

2、配置bootstrap.yml文件

注意:此處的配置文件需要放在bootstrap.properties或者是bootstrap.yml文件中,因?yàn)閏onfig的相關(guān)配置會(huì)先于application.properties,而bootstrap.properties的加載也是先于application.properties

server: 
 port: 8889 
spring: 
 application: 
  name: configserver  # 必須與配置文件的前綴一致,例如此處我們的配置文件名是configserver-dev.properties,則此處需配置成configserver 
 cloud: 
  config: 
   uri: http://localhost:8888/ //配置spring cloud config服務(wù)端的url 
   profile: dev           # 指定profile 
   label: master           # 指定gitlab倉(cāng)庫(kù)的分支

3、驗(yàn)證客戶端

在客戶端新增一個(gè)Controller

package com.chhliu.springcloud.config;  
import org.springframework.beans.factory.annotation.Value; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.cloud.context.config.annotation.RefreshScope; 
import org.springframework.web.bind.annotation.GetMapping; 
import org.springframework.web.bind.annotation.RestController;  
@SpringBootApplication 
@RestController 
@RefreshScope //注解@RefreshScope指示Config客戶端在服務(wù)器配置改變時(shí),也刷新注入的屬性值 
public class SpringcloudConfigClientApplication { 
 
  public static void main(String[] args) { 
    SpringApplication.run(SpringcloudConfigClientApplication.class, args); 
  } 
 
  @Value("${hello}") // 讀取gitlab配置文件中的屬性,如果我們讀取到了值,說(shuō)明客戶端是OK的 
  private String profile; 
 
  @GetMapping("/hello") 
  public String hello() { 
    return this.profile; 
  } 
}

在瀏覽器中訪問(wèn):http://localhost:8889/hello,結(jié)果如下:

i'm the king of the world!!! 

說(shuō)明客戶端已經(jīng)可以從服務(wù)端獲取到值了。

三、動(dòng)態(tài)刷新

無(wú)需重新啟動(dòng)客戶端,即可更新Spring Cloud Config管理的配置

1、更新gitlab倉(cāng)庫(kù)中configserver-dev.properties配置文件中hello對(duì)應(yīng)的屬性值

2、訪問(wèn)http://localhost:8888/configserver/dev/master,發(fā)現(xiàn)server端內(nèi)容已經(jīng)更新

3、對(duì)Conf客戶端發(fā)一個(gè)POST請(qǐng)求http://localhost:8889/refresh,返回200 OK。再次訪問(wèn)http://localhost:8889/hello,可見(jiàn)在并未重啟客戶端服務(wù)的情況下,讀到的屬性值已經(jīng)動(dòng)態(tài)更新

PS:要想實(shí)現(xiàn)動(dòng)態(tài)刷新,需要在pom文件中添加以下starter

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

讀到這里,這篇“spring cloud config整合gitlab如何搭建分布式的配置中心”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站標(biāo)題:springcloudconfig整合gitlab如何搭建分布式的配置中心
文章來(lái)源:http://www.rwnh.cn/article32/jgpdpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、建站公司網(wǎng)站排名、動(dòng)態(tài)網(wǎng)站標(biāo)簽優(yōu)化、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)
金溪县| 来凤县| 东乡| 丁青县| 淳安县| 霍邱县| 逊克县| 晋城| 丰宁| 邵阳县| 搜索| 温州市| 宁国市| 宁津县| 伊吾县| 宁都县| 抚松县| 铁岭市| 门源| 达孜县| 博兴县| 佛坪县| 南充市| 昌都县| 巴林右旗| 毕节市| 东安县| 千阳县| 扎赉特旗| 阿拉尔市| 略阳县| 策勒县| 仁布县| 漾濞| 新和县| 榆社县| 游戏| 隆子县| 合阳县| 哈尔滨市| 洪江市|