国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - 詳解spring cloud config整合gitlab搭建分布式的配置中心

詳解spring cloud config整合gitlab搭建分布式的配置中心

2021-03-24 15:17牛奮lch Java教程

這篇文章主要介紹了詳解spring cloud config整合gitlab搭建分布式的配置中心,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

在前面的博客中,我們都是將配置文件放在各自的服務(wù)中,但是這樣做有一個(gè)缺點(diǎn),一旦配置修改了,那么我們就必須停機(jī),然后修改配置文件后再進(jìn)行上線,服務(wù)少的話,這樣做還無可厚非,但是如果是成百上千的服務(wù)了,這個(gè)時(shí)候,就需要用到分布式的配置管理了。而spring cloud config正是用來解決這個(gè)問題而生的。下面就結(jié)合gitlab來實(shí)現(xiàn)分布式配置中心的搭建。spring cloud config配置中心由server端和client端組成,

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

一、配置Server

1、添加依賴

?
1
2
3
4
<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

2、在Application主類開啟支持

?
1
@EnableConfigServer

3、配置application.yml文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
server:
 port: 8888
spring:
 application:
  name: config
 cloud:
  config:
   server:
    git:
     uri: https://gitlab.xxx.com/xxxxx/xxxxx.git   # 配置gitlab倉庫的地址,注意,此處必須以.git結(jié)尾
     search-paths: /config-repo # gitlab倉庫地址下的相對(duì)地址,可以配置多個(gè),用,分割。
     username: your username                       # gitlab倉庫的賬號(hào)
     password: your password                       # gitlab倉庫的密碼

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
 
  "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上讀取到配置文件了。可以通過如下表單中的方式訪問gitlab上的資源

?
1
2
3
4
5
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

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

?
1
2
3
hello: i'm the king of the world!!!
name: chhliuxyh
profile: profile-default

二、配置客戶端

1、添加pom依賴

?
1
2
3
4
5
6
7
8
<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

?
1
2
3
4
5
6
7
8
9
10
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倉庫的分支

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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配置文件中的屬性,如果我們讀取到了值,說明客戶端是OK的
  private String profile;
 
  @GetMapping("/hello")
  public String hello() {
    return this.profile;
  }
}

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

i'm the king of the world!!! 

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

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

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

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

2、訪問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。再次訪問http://localhost:8889/hello,可見在并未重啟客戶端服務(wù)的情況下,讀到的屬性值已經(jīng)動(dòng)態(tài)更新

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

?
1
2
3
4
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/liuchuanhong1/article/details/60139828

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 动漫爱爱视频 | 精品中文字幕在线 | 日韩精品免费在线视频 | 黄色免费网站在线观看 | 欧美第8页 | 美女久久久 | 深夜视频在线 | 中文字幕亚洲一区 | 黄色一级免费大片 | 亚洲高清毛片一区二区 | 色站综合 | 国产一级一级国产 | 午夜视频在线免费观看 | 色久综合 | 久久中文字幕一区 | 一区二区日韩 | 欧美片网站免费 | 久久久成人免费一区二区 | 久久99精品久久久久久国产越南 | 日韩免费视频 | 久久久亚洲国产天美传媒修理工 | 午夜视频在线播放 | 午夜精品在线 | 国产乱码精品一区二区三区五月婷 | 天堂俺去俺来也www久久婷婷 | 亚洲欧洲视频 | 中文在线一区二区 | 日韩精品极品视频在线观看免费 | 亚洲激情网站 | 日韩三级在线免费观看 | 欧美黄色小视频 | 人人人人人你人人人人人 | 午夜精品美女久久久久av福利 | 国产欧美日韩综合精品一区二区 | 国产精品中文字幕在线观看 | 色中色综合 | 亚洲精品乱码久久久久久蜜桃不爽 | 亚洲精品国产一区 | av毛片| 国产精品久久久久无码av | 欧美成人高清 |