spring cloud config是spring cloud团队创建的一个全新的项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端和客户端两部分。

服务端也被称为配置中心,其除了可以在spring构建的应用程序中使用也可以在其它语言运行的程序中使用。

构建配置中心:

新建项目命名为config-server并且添加config-server的依赖

主类中加入@EnableConfigServer注解,开启Spring Cloud Config的服务端功能

在application.properties中添加配置服务的基本信息以及Git仓库的相关信息

spring.application.name=config-server
server.port=7001
# 配置Git仓库位置
spring.cloud.config.server.git.uri=http://172.16.99.16/rxhan/test.git
# 配置仓库路径下的相对搜索位置
spring.cloud.config.server.git.searchPaths=config-repo
# Git仓库访问的用户名
spring.cloud.config.server.git.username=rxhan@travelsky.com
# Git仓库访问的密码
spring.cloud.config.server.git.password=12345678

到这里,使用一个通过Spring Cloud Config实现,并使用Git管理配置内容的分布式配置中心就完成了。启动项目。

配置规则详解:

为了验证配置中心,我们在Git仓库下创建config-repo如下目录

并根据环境创建出不同的文件

didispace.properties

didispace-dev.properties

didispace-test.properties

didspace-prod.properties

在四个配置文件中均设置一个from属性,并未每个配置文件分别设置不同的值

from=git-default-1.0

from=git-dev-1.0

from=git-test-1.0

from=git-prod-1.0

访问测试

http://localhost:7001/didispace/dev

客户端配置:

创建项目 config-client 并加入config依赖和web依赖

加入如下配置文件

bootstrap.properties

spring.application.name=didispace
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.uri=http://localhost:7001/
server.port=7002

新建测试controller

访问测试

http://localhost:7002/from

至此基于spring cloud config的配置中心及客户端配置完成。

Spring Cloud Config 1 (分布式配置中心)的更多相关文章

  1. 【Spring Cloud】Spring Cloud Config 实现分布式配置中心

    Spring Cloud Config 实现分布式配置中心 一.分布式配置中心 分布式系统中,往往拥有大量的服务应用,而每个应用程序都需要有对应的配置文件来协助完成服务环境初始化.运行.因此生产了大量 ...

  2. SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心

    目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...

  3. Spring Cloud(九):分布式配置中心和消息总线

    我们在Spring Cloud(七):使用SVN存储分布式配置中心文件和实现refresh中讲到,如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码 ...

  4. Spring Cloud(八):分布式配置中心服务化和高可用

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...

  5. Spring Boot + Spring Cloud 实现权限管理系统 配置中心(Config、Bus)

    技术背景 如今微服务架构盛行,在分布式系统中,项目日益庞大,子项目日益增多,每个项目都散落着各种配置文件,且随着服务的增加而不断增多.此时,往往某一个基础服务信息变更,都会导致一系列服务的更新和重启, ...

  6. spring cloud深入学习(七)-----配置中心git示例

    随着线上项目变的日益庞大,每个项目都散落着各种配置文件,如果采用分布式的开发模式,需要的配置文件随着服务增加而不断增多.某一个基础服务信息变更,都会引起一系列的更新和重启,运维苦不堪言也容易出错.配置 ...

  7. Spring Cloud 入门教程 - 搭建配置中心服务

    简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...

  8. 【Spring Cloud学习之五】配置中心

    环境 eclipse 4.7 jdk 1.8 Spring Boot 1.5.2 Spring Cloud 1.2 一.什么是配置中心在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实 ...

  9. Spring Cloud 系列之 Apollo 配置中心(三)

    本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Apollo 配置中心(一) Spring Cloud 系列之 Apollo 配置中心(二) 本篇文章讲解 Apol ...

  10. Spring Cloud Zuul 2(基于配置中心的动态API网关)

    在大体了解了API Zuul 和 配置中心Config后我们来尝试完成一个基于配置中心的动态API网关 创建项目 命名为api-gateway-dynamic-route并加入config 和 Zuu ...

随机推荐

  1. UI-UIScrollView

    - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMa ...

  2. selenium2中关于Python的常用函数

    driver = webdriver.Chrome(chromeDriver) 1.返回当前会话中的cookies:driver.get_cookies() 2.根据cookies name查找:dr ...

  3. 在Ubuntu 14.04 TLS下openvas V8.0源代码安装过程

    [Qboy原创]详细记录源代码的安装过程 1.下载原代码 在http://www.openvas.org/install-source.html下载 Libraries 8.0.8 Scanner 5 ...

  4. javascript 的智能提示intellisence用法

    转载自:http://blog.csdn.net/applewangpai/article/details/23517087   引用指令reference Visual Studio 2012支持的 ...

  5. RAD Studio Mobile Roadmap updated,XE5 will released on next month, Andriod will be supported.

    RAD Studio Mobile Roadmap updated   Embarcadero updated his RAD Studio Mobile Roadmap. This concern ...

  6. 9.链表中倒数第k个结点[FindReverseKthLinkedListNode]

    [题目] 输入一个单向链表,输出该链表中倒数第k个结点.链表的倒数第0个结点为链表的尾指针.链表结点定义如下:  C++ Code  12345   struct ListNode {     int ...

  7. php 中 用curl 发送 https 请求

    在 php.ini 中修改配置选项 curl.cainfo = "D:\phpStudy\php\php-5.6.27-nts\pert\cacert.pem" 其中 cacert ...

  8. SHELL 脚本----常用的命令

    一个很不错的bash脚本编写教程,至少没接触过BASH的也能看懂   建立一个脚本 Linux中有好多中不同的shell,但是通常我们使用bash (bourne again shell) 进行she ...

  9. 网络爬虫必备知识之urllib库

    就库的范围,个人认为网络爬虫必备库知识包括urllib.requests.re.BeautifulSoup.concurrent.futures,接下来将结合爬虫示例分别对urllib库的使用方法进行 ...

  10. LeetCode Kill Process

    原题链接在这里:https://leetcode.com/problems/kill-process/description/ 题目: Given n processes, each process ...