springboot配置文件抽离 git管理统 配置中心详解
作者:yu_fly 时间:2021-05-24 08:17:18
springboot配置文件抽离,便于服务器读取对应配置文件,避免项目频繁更改配置文件,影响项目的调试与发布
1.创建统一配置中心项目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.创建git私有项目config-repo 用于存放配置文件
3.配置项目 可以看到对应的配置文件内容
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
来源:https://www.cnblogs.com/flyyu1/p/11445723.html
标签:springboot,配置文件,git管理统,配置中心
0
投稿
猜你喜欢
Python深度学习之Unet 语义分割模型(Keras)
2022-10-18 13:30:15
详解Django+Uwsgi+Nginx的生产环境部署
2022-10-30 10:54:17
经验总结:修改MySQL默认密码的具体步骤
2009-01-04 13:29:00
go语言题解LeetCode66加一示例详解
2024-05-13 10:43:47
Python开发的HTTP库requests详解
2021-09-06 19:08:09
一个js封装的不错的选项卡效果代码
2024-02-26 11:23:59
如何用vue实现网页截图你知道吗
2024-04-27 15:51:31
php中debug_backtrace、debug_print_backtrace和匿名函数用法实例
2023-06-11 23:08:24
Sql Server2005对现有数据进行分区具体步骤
2008-06-26 13:18:00
python实现学生信息管理系统
2021-11-27 11:46:42
python实现多线程的方式及多条命令并发执行
2023-08-09 11:37:20
CSS hacks与争议
2007-11-19 12:56:00
python中threading超线程用法实例分析
2023-12-14 13:05:45
Python实现二维数组输出为图片
2022-10-07 21:49:55
使用Matlab将矩阵保存到csv和txt文件
2022-11-25 16:08:35
python自动化之Ansible的安装教程
2023-06-28 13:58:23
asp中利用xmlhttp抓取网页内容的代码
2023-07-06 04:18:12
Python enumerate索引迭代代码解析
2022-04-05 17:13:07
python入门之语句(if语句、while语句、for语句)
2022-01-25 20:01:07
Python Socketserver实现FTP文件上传下载代码实例
2022-10-10 11:03:04