springboot配置文件抽離 git管理統(tǒng) 配置中心詳解
springboot配置文件抽離,便于服務(wù)器讀取對應(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)目 可以看到對應(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ī)時關(guān)閉eureka 保護(hù)模式
lease-expiration-duration-in-seconds: 2
以上就是本次介紹的關(guān)于springboot配置文件抽離 git管理統(tǒng) 配置中心全部知識點(diǎn)內(nèi)容,感謝大家對腳本之家的支持。
相關(guān)文章
python實(shí)現(xiàn)獲取當(dāng)前設(shè)備的地點(diǎn)位置
這篇文章主要介紹了python實(shí)現(xiàn)獲取當(dāng)前設(shè)備的地點(diǎn)位置,電腦如何獲取當(dāng)前所處的地理位置?它不會像我們一樣對地理位置有感性的認(rèn)知,它只認(rèn)識數(shù)據(jù),簡言之,電腦可以通過獲取當(dāng)前連接的公網(wǎng)IP,反推所處的位置環(huán)境,需要的朋友可以參考一下2022-03-03
利用python實(shí)現(xiàn)JSON文檔與Python對象互相轉(zhuǎn)換
這篇文章主要介紹了利用python實(shí)現(xiàn)JSON文檔與Python對象互相轉(zhuǎn)換,通過對將一個JSON文檔映射為Python對象問題的展開介紹主題內(nèi)容,需要的朋友可以參考一下2022-06-06
python實(shí)現(xiàn)發(fā)送郵件功能代碼
這篇文章主要介紹了python實(shí)現(xiàn)發(fā)送郵件功能代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12
python實(shí)現(xiàn)輸入三角形邊長自動作圖求面積案例
這篇文章主要介紹了python實(shí)現(xiàn)輸入三角形邊長自動作圖求面積案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04

