Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理
开源配置中心:
1.百度Disconf
2.阿里Diamand
3.Spring Cloud Config
搭建Config-Server
快速上手:

选择依赖:Eureka和Config
选取Eureka原因:保证高可用

启动类加入注解:
package org.dreamtech.configserver; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
} }
配置:
Eureka-Server的搭建:https://www.cnblogs.com/xuyiqing/p/10861541.html
使用Git服务器:我使用的是Github,新建一个测试仓库
spring.application.name=config-server
server.port=9100
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
spring.cloud.config.server.git.uri=https://github.com/EmYiQing/SpringCloudTest
spring.cloud.config.server.git.username=EmYiQing
spring.cloud.config.server.git.password=xxxxxx
在Github上新建一个配置文件做测试:

测试:
启动项目Eureka-Server->Config-Server
查看注册中心:成功

访问localhost:9100:报错
访问http://localhost:9100/product-service.yml:拿到刚才在Github新建的配置文件,成功
如果我们访问http://localhost:9100/product-service.properties?
那么Config会直接把YML转化为properties文件,很强大
注意:Git上的配置文件格式一定不能出错
还可以做一些默认配置:比如超时时间和默认分支
spring.cloud.config.server.git.timeout=5
spring.cloud.config.server.git.default-label=master
有了Server当然也要有Client:
在服务模块引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
将配置文件application.yml更名为bootstrap.yml:
进行三项配置:
1.Eureka-Server-URL
2.该服务模块名称
3.Config配置中心在Eureka-Server的名称和启用
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: product-service
cloud:
config:
discovery:
service-id: CONFIG-SERVER
enabled: true
启动项目耗时将会更长,因为读取Git服务器配置文件是耗时的操作
Config配置中心使用的注意事项:
1.保证Git服务器的配置文件格式正确
2.Git服务器的配置文件建议采用分支进行区分,不推荐使用后缀区分
比如使用/test/product-service.yml代替/product-service-test.yml
然而到这里还是没有结束,比如配置文件的动态更新等等,这些功能在以后实现
Spring Cloud(9):Config配置中心的更多相关文章
- Spring Cloud 2-Config 分布式配置中心(七)
Spring Cloud Config 1.github配置 2.服务端配置 pom.xml application.xml Application.java 3.配置和命名 1. 配置加载顺序 ...
- Spring Cloud Consul使用——配置中心
1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...
- spring cloud学习(六) 配置中心-自动更新
上一篇学习了spring cloud config的基本使用,但发现有个问题,就是每次更改配置后,都需要重启服务才能更新配置,这样肯定是不行的.在上网查资料了解后,spring cloud支持通过AM ...
- spring cloud学习(五) 配置中心
Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务中心采用Git的方式存储配置文件,因此我们很容易部署修改,有助于对环境配置进行版本管理. 一.配置中心 ...
- Spring Cloud (6) 分布式配置中心-高可用
高可用 现在已经可以从配置中心读取配置文件了,当微服务很多时都从配置中心读取配置文件,这时可以将配置中心做成一个微服务,将其集群化,从而达到高可用. 改造config-server 加入eureka ...
- Spring Cloud (5) 分布式配置中心
Spring Cloud Config 在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,使用Spring Cloud ...
- spring cloud 集成分布式配置中心 apollo(单机部署apollo)
一.什么是apollo? Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用 ...
- Spring Cloud Gateway 结合配置中心限流
前言 上篇文章我讲过复杂的限流场景可以通过扩展RedisRateLimiter来实现自己的限流策略. 假设你领导给你安排了一个任务,具体需求如下: 针对具体的接口做限流 不同接口限流的力度可以不同 可 ...
- Spring Cloud之分布式配置中心
用服务的方式来实现 ConfigAppApplication.java package com.packtpub.ConfigApp; import org.springframework.boot. ...
- Spring Cloud Alibaba nacos 配置中心使用
背景 上一文我们讲到了如何去搭建注册中心,这一次我们讲述如何使用nacos作为注册中心 spring-cloud-alibaba-basis 创建基础依赖 首先我们创建一个spring-cloud-a ...
随机推荐
- HEVC标准介绍+论文阅读笔记
脱离视频编解码.投入计算机视觉一年,这个博客也歇业一年,最近偷些时间回顾一下编解码,毕竟花费了整个研一的时间(虽然这一年基本上在上课). 之前写过几篇H.264标准的几篇介绍文章,详见:http:// ...
- Eclipse--java.lang.OutOfMemoryError: PermGen space
这一段时间,Eclipse总是死掉,几乎是稍微操作快一点就会死掉,几分钟一次,搞得人郁闷至极.浪费了不少时间,在网上搜了下,看到很多朋友也出现类似的情况,在网上求救,但是网上的办法都只是说通过修改ec ...
- java web开发中常用的协议的使用和java-web 常见的缓冲技术
一.DNS协议 作用将域名解析为IP 类似于我们只需要知道中央一台,中央二台,而不需要知道它的频率,方便记忆. java dns 域名解析协议实现 1 域名解析,将域名可转换为ip地址InetAd ...
- Window服务程序(windows service application)如何调试
服务程序不能通过常规的按F5或F11的方式来进行调试和运行,也无法立即运行一个服务或逐步调试它的代码. 因此,你必须安装并启动你的服务,然后附属(attach)一个Debugger到这个服务的进程上.
- Word转html并移植到web项目
1.打开对应word文件 建议使用web视图查看文档 这样可以提前预览转转成html样式 2.如果有图片修改图片大小及格式 在web视图下,把图片调制适当大小,不然导出的html可能图片较小 3.点击 ...
- 169. Majority Element@python
Given an array of size n, find the majority element. The majority element is the element that appear ...
- POJ-1190 蛋糕问题
这道题目我们使用深搜加剪枝的方法来写,我们首先算出一个最小表面积和最小体积来,就是半径从一递增,高度也从一递增,这是题目要求. 然后我们计算出一个底层最大的半径和最大的高度,我们就从这个最大半径和最大 ...
- [模板] Miller-Rabin 素数测试
细节挺多的.. #include<iostream> #include<cstdlib> #include<cstdio> #include<ctime> ...
- Python自动化测试框架——断言
在自动化测试执行的过程中,我们往往希望可以自定生成报告,那如何再测试中进行验证呢?我们使用断言 import unittest class TestCount(unittest.TestCase): ...
- git 知识(转)
转自:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html Workspace:工作区 Index / Stage:暂存区 Repos ...