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 ...
随机推荐
- 自欺欺人的使用 NSTimer 销毁
自欺欺人的使用 NSTimer 销毁 Demo地址 1.NSTimer是要加到runloop中才会起作用. 常见的创建timer方式 // 第一种方式 @property (nonatomic , s ...
- SQLite -插入查询
SQLite -插入查询 SQLite插入语句是用来添加新行数据到数据库中的一个表. 语法: 有两种基本的插入语句的语法如下: INSERT INTO TABLE_NAME (column1, co ...
- 【整理】iview中刷新页面的时候更新导航菜单的active-name
iview中刷新页面的时候更新导航菜单的active-name https://blog.csdn.net/lhjuejiang/article/details/83212070
- python猜年龄游戏升级版
猜年龄游戏升级版 要求:允许用户最多尝试3次,每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y,就继续让其猜3次,以此往复,如果回答N,就退出程序,如何猜对了,就直接退出 age = 1 ...
- 网络设置命令--ifconfig.setup
ifconfig命令 作用:用于显示以及设置当前活动网卡信息 一. 显示当前活动网卡信息 ifconfig 从上面可以看到当前主要有2块活动网卡,eth0:代表当前本地真实网卡 lo:代表回访网卡, ...
- OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档ID 1410.1)
OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档I ...
- Nginx 跨域
if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access- ...
- NowCoder小杰的签到题(模拟,思维)
链接: https://www.nowcoder.com/acm/contest/52/M 题意: 给定n个队伍的到场时间, 有3个报道位, 每个队伍报道需要b时间, 求所有报道完成的时间. 分析: ...
- openstack创建虚拟机之后使用ssh登陆的解决办法
创建一个虚机之后:若果想要在horizon的控制台上登录操作,第一步.需要先使用ssh从controller上修改密码 从controller上登录: ssh ubuntu@虚机ip sudo su ...
- 分享21个基于jquery菜单导航的效果
jquery导航菜单插件制作jquery动画菜单熔岩灯菜单效果更新时间:02月15日 14:53:03 虾米精选-菜单导航-导航菜单 0浏览 / ★★★☆☆星级 / 未知软件大小/ jquery导航菜 ...