springboot配置文件抽離 git管理統(tǒng) 配置中心詳解
springboot配置文件抽離,便于服務器讀取對應配置文件,避免項目頻繁更改配置文件,影響項目的調(diào)試與發(fā)布
1.創(chuàng)建統(tǒ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私有項目config-repo 用于存放配置文件
3.配置項目 可以看到對應的配置文件內(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 # 單機時關閉eureka 保護模式
lease-expiration-duration-in-seconds: 2
以上就是本次介紹的關于springboot配置文件抽離 git管理統(tǒng) 配置中心全部知識點內(nèi)容,感謝大家對腳本之家的支持。
相關文章
Python3遠程監(jiān)控程序的實現(xiàn)方法
今天小編就為大家分享一篇Python3遠程監(jiān)控程序的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07
Python根據(jù)輸入?yún)?shù)計算結果的實例方法
在本篇文章里小編個大家整理了一篇關于Python根據(jù)輸入?yún)?shù)計算結果的實例方法,有興趣的朋友們可以跟著學習參考下。2021-08-08

