springboot配置文件抽離 git管理統(tǒng) 配置中心詳解
springboot配置文件抽離,便于服務(wù)器讀取對(duì)應(yīng)配置文件,避免項(xiàng)目頻繁更改配置文件,影響項(xiàng)目的調(diào)試與發(fā)布
1.創(chuàng)建統(tǒng)一配置中心項(xiàng)目conifg
1)pom配置依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2)yml文件配置
spring:
application:
name: config
cloud:
config:
server:
git:
uri: https://gitee.com/XXXX/XXXXXX.git
username: XXXXXXX
password: XXXXXXXXX
eureka:
client:
service-url:
defaultZone: http://localhost:8000/eureka/
management:
endpoints:
web:
expose: "*"
2.創(chuàng)建git私有項(xiàng)目config-repo 用于存放配置文件
3.配置項(xiàng)目 可以看到對(duì)應(yīng)的配置文件內(nèi)容
http://localhost:8002/XXXXX/user-dev.yml
4.配置客戶端讀取配置文件
1)客戶端配置pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-client</artifactId> </dependency>
2)客戶端yml文件配置
spring:
application:
name: XXXXXX
cloud:
config:
discovery:
enabled: true
service-id: CONFIG
profile: dev
eureka:
client:
service-url:
defaultZone: http://localhost:8000/eureka/
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 1 # 單機(jī)時(shí)關(guān)閉eureka 保護(hù)模式
lease-expiration-duration-in-seconds: 2
以上就是本次介紹的關(guān)于springboot配置文件抽離 git管理統(tǒng) 配置中心全部知識(shí)點(diǎn)內(nèi)容,感謝大家對(duì)腳本之家的支持。
相關(guān)文章
PHP基于phpqrcode類庫(kù)生成二維碼過(guò)程解析
這篇文章主要介紹了PHP基于phpqrcode類庫(kù)生成二維碼過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
解讀python如何實(shí)現(xiàn)決策樹(shù)算法
在本篇文章里我們給讀者們分享了關(guān)于python如何實(shí)現(xiàn)決策樹(shù)算法的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們參考下。2018-10-10
Python3遠(yuǎn)程監(jiān)控程序的實(shí)現(xiàn)方法
今天小編就為大家分享一篇Python3遠(yuǎn)程監(jiān)控程序的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07
Python根據(jù)輸入?yún)?shù)計(jì)算結(jié)果的實(shí)例方法
在本篇文章里小編個(gè)大家整理了一篇關(guān)于Python根據(jù)輸入?yún)?shù)計(jì)算結(jié)果的實(shí)例方法,有興趣的朋友們可以跟著學(xué)習(xí)參考下。2021-08-08

