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

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 特级www| 特黄特黄一级高清免费大片 | 国产农村乱子伦精品视频 | 日韩夫妻性生活 | 美女被吸乳得到大胸 | 日本高清中文字幕 | 精品国产一区二区三区久久久蜜臀 | 青草久久精品亚洲综合专区 | 日韩大片免费看 | 69日本xxxxxxxxx98 69人成网站色www | 亚洲日韩欧美一区二区在线 | 洗濯屋H纯肉动漫在线观看 武侠艳妇屈辱的张开双腿 午夜在线观看免费观看 视频 | 91精品国产在线 | 亚洲精品AV无码永久无码 | 青柠在线完整高清观看免费 | 啪啪导航 | 视频免费视频观看网站 | haodiaose在线精品免费视频 | 国产黑丝一区 | 麻豆资源| 天天久久综合网站 | ferr孕妇videos毛茸茸 | 亚洲国产在线播放 | 国产欧美精品一区二区三区四区 | 荡女人人爱全文免费阅读 | 草莓视频榴莲视频 | 星球大战成人h无删减版 | 操美女| 奇米影视4444| 欧美亚洲天堂网 | 香蕉视频在线观看网站 | 男神插曲女生动漫完整版动漫 | 先锋影音 av | 天天综合色天天综合网 | 男人j桶进女人p桶爽 | 精品一区二区三区色花堂 | 91大神第九部红酒气质女 | 草草国产成人免费视频 | 99热在线只有精品 | 免费观看欧美成人禁片 | 91东航翘臀女神在线播放 |