•Spring Cloud分布式配置服务由服务器端和客户端共同组成,Server端提供配置信息的存储管理,客户端完成配置信息的调度
•spring Cloud Config项目提供了一个解决分布式系统的配置管理方案。它包含了Client和Server两个部分。
•Spring Cloud Config Sever的管理Git,svn, native的外部配置,集中配置到所有客户端。
•Spring Cloud Config Client根据Spring框架的Environment和PropertySource从Spring Cloud Config Sever获取配置。
•资源信息遵循如下规则:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
/application.properties
Server
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
spring.cloud.config.server.native.searchLocations=file:E://git//config-repo//config
#git 配置
spring.cloud.config.server.git.uri=https://github.com/zhaoqilong3031/sprng-config-repo.git
spring.cloud.config.server.git.searchPaths={application}
spring.cloud.config.server.git.cloneOnStart=true
spring.cloud.config.server.git.username=git@user.com
spring.cloud.config.server.git.password=password
#系统
server.port=7071
server.context-path=/
server.uri-encoding=utf-8
spring.application.name=config
management.context-path=/management
management.address=127.0.0.1
info.app.name=${spring.application.name}
info.app.profiles=${spring.profiles.active}
info.app.version=@project.version@
#native 本地 native , git server
spring.profiles.active=git
#安全
security.basic.enabled=false
security.user.name=test
security.user.password=test
security.ignored=/management/**
client
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
spring.cloud.config.name=${spring.application.name}
spring.cloud.config.profile=@spring.cloud.config.profile@
spring.cloud.config.label=master
spring.cloud.config.uri=@spring.cloud.config.uri@
spring.cloud.config.username=@spring.cloud.config.username@
spring.cloud.config.password=@spring.cloud.config.password@
spring.cloud.config.failFast=true
spring.profiles.active=@env@
详细匹配可参考https://springcloud.cc/spring-cloud-config-zhcn.html