什么是统一配置管理
spring cloud config为分布式系统外部化配置提供了服务器和客户端的支持.他包括config server和config client 两部分. 由于config server和config client 都实现了对spring environment(环境)和property source(属性源)抽象映射,因此,spring cloud config非常适合spring应用程序.当然也可以与任何其他语言编写的应用程序配合使用.
config server是一个可横向拓展,集中式的配置服务器,他用于集中管理应用程序各个环境下的配置,默认使用git存储配置内容.因此可以很方便的实现对配置的版本控制与内容审计.
config client 是config server的客户端,用于操作存储在config server中的配置属性.
为什么要统一配置管理
配置集中管理
不同环境不同配置
运行期间动态调整配置
自动刷新
架构图
配置、依赖
该项目(XXXXX-config)必须也是eureka服务
- 在github上创建文件
2.pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
3.application.yml
spring:
application:
name: jwxt-config #指定服务名
cloud:
config:
label: master
server:
git:
uri: https://github.com/hanxuesong123/jwxt-config
username: 1323232302@qq.com
password: hanzhibin1
- 启动类
@EnableConfigServer
<服务端>
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
application.xml
spring:
cloud:
config:
uri: http://localhost:8888
label: master
name: application-teacher
profile: dev