一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - 詳解SpringCloud Config配置中心

詳解SpringCloud Config配置中心

2021-07-20 16:07liuhh Java教程

這篇文章主要介紹了詳解SpringCloud Config配置中心,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

一、創建config配置中心項目

1.添加依賴

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

2.啟動類,需要添加@enableconfigserver

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import org.springframework.boot.springapplication;
import org.springframework.boot.autoconfigure.springbootapplication;
import org.springframework.cloud.config.server.enableconfigserver;
 
/**
 * @author fusw
 */
@springbootapplication
@enableconfigserver
public class configcenterapplication {
 
  public static void main(string[] args) {
    springapplication.run(configcenterapplication.class, args);
  }
 
}

3.配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
eureka.instance.appname=base-iov-config
security.user.name=test
security.user.password=test
# gitlab 的配置方式,必須有 .git 后綴
# 配置默認 git 倉庫的地址
spring.cloud.config.server.git.uri=http://xxxx/config-repo.git
# git 倉庫地址下的相對地址,可以配置多個,用“,”分割
spring.cloud.config.server.git.search-paths=*
#配置中心clone倉庫配置文件后存放的地址
spring.cloud.config.server.git.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.force-pull=true
# git 倉庫的賬號
spring.cloud.config.server.git.username=test
# git 倉庫的密碼
spring.cloud.config.server.git.password=test
 
 
 
# 配置 其它git 倉庫的地址 spring.cloud.config.server.git.repos.x.uri, iot為例
spring.cloud.config.server.git.repos.iot.uri=http://xxxx/iot/config-repo.git
spring.cloud.config.server.git.repos.iot.search-paths=*
spring.cloud.config.server.git.repos.iot.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.repos.iot.force-pull=true
# git 倉庫的賬號
spring.cloud.config.server.git.repos.iot.username=test
# git 倉庫的密碼
spring.cloud.config.server.git.repos.iot.password=test
#前綴一定要配置,用來和默認倉庫區分
spring.cloud.config.server.git.repos.iot.pattern=iot*
 
#注冊中心
eureka.client.serviceurl.defaultzone=http://xxx/eureka/

二、git 存放配置的倉庫

創建一個git倉庫用來存放各項目配置,可以在項目一級目錄根據項目創建文件夾(各項目文件夾的名稱可以隨便起,config配置中心只根據配置文件名找配置),然后各個項目文件夾存放不同環境的配置文件,

例如:

iot-testproject-dev.yml
iot-testproject-prd.yml
iot-testproject-test.yml

最好不要放置test.yml類似的默認配置,如果在各個項目配置文件中沒有用spring.profiles.active指明使用的配置文件,那么會加載默認的配置文件。

三、各個springcloud的項目配置接入配置中心

在resource下的bootstrap.properties配置文件中,配置中心的相關配置如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 使用默認倉庫的配置文件
spring.cloud.config.name=testproject
# 使用iot廠庫的配置文件
#spring.cloud.config.name=iot-testproject
#使用哪個環境的配置文件,和上面的配置配合,決定了使用哪一個配置文件:testproject -test.yml
spring.cloud.config.profile=test
 
 
# 對應 存放配置文件倉庫的git分支
spring.cloud.config.label=master
 
spring.cloud.config.username=test
spring.cloud.config.password=test
 
# 開啟 config 服務發現支持
spring.cloud.config.discovery.enabled=true
# 指定 server 端的 name,也就是 server 端 spring.application.name 的值
spring.cloud.config.discovery.serviceid=base-iov-config

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://segmentfault.com/a/1190000018437089

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 女同学用白丝脚玩我的故事 | 红杏劫 | 激情视频网址 | 我年轻漂亮的继坶2中字在线播放 | 亚洲视频免费在线看 | 国产动作大片 | 欧美乱妇高清无乱码视频在线 | 手机跑分排行最新排名 | yellow视频免费观看播放 | 国产精品久久久久久爽爽爽 | 精品一成人岛国片在线观看 | 久久精品中文字幕 | 毛毛片在线 | 国产精品99在线观看 | 女主被当众调教虐np | 亚洲乱亚洲23p女 | 草莓影音 | 99 久久99久久精品免观看 | 香蕉久久一区二区三区啪啪 | 猫咪社区免费资源在线观看 | 国产伦精品一区二区三区免费观看 | 精品区2区3区4区产品乱码9 | 欧美草比视频 | 亚州人成网在线播放 | bbbxxx乱大交欧美小说 | 五月天中文在线 | 美女翘臀内疯狂进出 | 好姑娘在线视频观看免费 | 国产香蕉97碰碰久久人人 | 黄蓉h系列 | 1769亚洲欧美资源站 | 欧美 变态 另类 人妖班 | 四虎精品成人a在线观看 | 欧美人伦禁忌.5 | 97伊人久久精品亚洲午夜 | 亚洲乱码一区二区三区国产精品 | 国产高清一区二区 | 22222色男人的天堂 | 国产高清不卡码一区二区三区 | 亚洲精品久久啪啪网站成年 | 国产精品久久久久久久久久久威 |