微服务意味着将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中出现大量的服务。由于每个服务都需要配置必要的配置信息才能运行,所以一套集中式的、动态的配置管理设施是必不可少的。Spring Cloud提供了ConfigServer来解决这个问题,我们每一个微服务自己都带着application.yml,上百个配置文件的管理……接下来你会疯的。
SpringCloud Config为微服务架构中的微服务提供了集中化的外部配置支持,配置服务器为各个不同微服务应用的所有环境提供了一个中心化的外部配置。
SpringCloud Config分为服务端和客户端:
服务端:也被称为分布式配置中心,它是一个独立的微服务应用,用来连接配置服务器并为客户端提供获取配置信息,加密/解密信息等访问接口。
客户端:通过指定的配置中心来管理应用资源,以及与业务相关的配置内容,并在启动的时候从配置中心获取和加载配置信息,配置服务器默认采用git来存储配置信息,这样有助于对环境配置进行版本管理,并且可以用过git客户端工具来方便的管理和访问配置内容。
我这里已经建好地址:https://github.com/Simple-Coder/microservice-config
spring:
profiles:
active:
- dev
---
spring:
profiles: dev #开发环境
application: microservice-config-dev
---
spring:
profiles: test #测试环境
application:
name: microservice-config-test
#保存为utf-8格式
<dependencies> <!--config server--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> </dependencies>
server:
port: 3344
spring:
application:
name: microservice-config
cloud:
config:
server:
git:
uri: git@github.com:Simple-Coder/microservice-config.git #github上的仓库地址
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
注:配置读取规则!
至此,成功实现了用SpringCloud Config通过github获取配置信息
SpringCloud全家桶学习之分布式配置中心----Config(七)
原文:https://www.cnblogs.com/rmxd/p/11570819.html