Home > Archives > 微服务:Config Server

微服务:Config Server

Publish:

Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持。配置服务器为各应用的所有环境提供了一个中心化的外部配置。它实现了对服务端和客户端对Spring Environment和PropertySource抽象的映射,所以它除了适用于Spring构建的应用程序,也可以在任何其他语言运行的应用程序中使用。作为一个应用可以通过部署管道来进行测试或者投入生产,我们可以分别为这些环境创建配置,并且在需要迁移环境的时候获取对应环境的配置来运行。

配置服务器默认采用git来存储配置信息,这样就有助于对环境配置进行版本管理,并且可以通过git客户端工具来方便的管理和访问配置内容。当然他也提供本地化文件系统的存储方式,下面从这两方面介绍如何使用分布式配置来存储微服务应用多环境的配置内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.baoguoding.configcenter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@EnableConfigServer
@SpringBootApplication
public class ConfigcenterApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigcenterApplication.class, args);
	}

}
1
2
3
4
5
6
7
spring.application.name=config-server
server.port=7001

spring.cloud.config.server.git.uri=https://github.com/baoguoding/springcloud
spring.cloud.config.server.git.searchPaths=config-server
spring.cloud.config.server.git.username=******
spring.cloud.config.server.git.password=******
1
server.port=7002
1
2
3
4
5
spring.application.name=center
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.uri=http://127.0.0.1:7001/
management.endpoints.web.exposure.include=*

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo