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配置中心的更多相关文章

  1. Spring Cloud 2-Config 分布式配置中心(七)

    Spring Cloud  Config  1.github配置 2.服务端配置 pom.xml application.xml Application.java 3.配置和命名 1. 配置加载顺序 ...

  2. Spring Cloud Consul使用——配置中心

    1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  3. spring cloud学习(六) 配置中心-自动更新

    上一篇学习了spring cloud config的基本使用,但发现有个问题,就是每次更改配置后,都需要重启服务才能更新配置,这样肯定是不行的.在上网查资料了解后,spring cloud支持通过AM ...

  4. spring cloud学习(五) 配置中心

    Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务中心采用Git的方式存储配置文件,因此我们很容易部署修改,有助于对环境配置进行版本管理. 一.配置中心 ...

  5. Spring Cloud (6) 分布式配置中心-高可用

    高可用 现在已经可以从配置中心读取配置文件了,当微服务很多时都从配置中心读取配置文件,这时可以将配置中心做成一个微服务,将其集群化,从而达到高可用. 改造config-server 加入eureka ...

  6. Spring Cloud (5) 分布式配置中心

    Spring Cloud Config 在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,使用Spring Cloud ...

  7. spring cloud 集成分布式配置中心 apollo(单机部署apollo)

    一.什么是apollo? Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用 ...

  8. Spring Cloud Gateway 结合配置中心限流

    前言 上篇文章我讲过复杂的限流场景可以通过扩展RedisRateLimiter来实现自己的限流策略. 假设你领导给你安排了一个任务,具体需求如下: 针对具体的接口做限流 不同接口限流的力度可以不同 可 ...

  9. Spring Cloud之分布式配置中心

    用服务的方式来实现 ConfigAppApplication.java package com.packtpub.ConfigApp; import org.springframework.boot. ...

  10. Spring Cloud Alibaba nacos 配置中心使用

    背景 上一文我们讲到了如何去搭建注册中心,这一次我们讲述如何使用nacos作为注册中心 spring-cloud-alibaba-basis 创建基础依赖 首先我们创建一个spring-cloud-a ...

随机推荐

  1. Android(java)学习笔记180:多媒体之图形的变化处理

    1. 图形的缩放 (1)布局文件activity_main.xml如下: <LinearLayout xmlns:android="http://schemas.android.com ...

  2. laravel homestead comoser install 报错

    项目部署的时候composer install报错 说那个依赖包没有安装成功需要回滚删除但是删除不了 解决: 要配置共享文件 注:使用 NFS 的话,需要安装 vagrant-winnfsd 插件.该 ...

  3. JavaScript-基础类型和运算符

    JavaScript-基础类型和运算符 P02.稍微了解 1.js代码需要编写到script标签中 <script type="text/javascript"> 此处 ...

  4. swift学习——枚举

    swift枚举 1. 枚举基本语法 enum Method { case Add case Sub case Mul case Div } 也可以使用一种更简单的写法 enum Method1{ ca ...

  5. Perl: hash散列转换为Json报错集, perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $

    bash-2.03$ ./u_json.pl Can't locate object method "encode" via package "JSON" at ...

  6. ES6 第一章 let和const命令 具体参照http://es6.ruanyifeng.com

    1.let类似于var用用来定义变量 1)let没有预解析,不存在变量提升 // var 的情况 console.log(foo); // 输出undefined var foo = 2; // le ...

  7. 第4节 hive调优:动态分区调整问题

    执行如下截图中的语句时卡住了: 原因:yarn未启动,hive底层是要提交mapreduce到yarn上才能计算结果的. 之前启动yarn时,未执行jps查看是否已经启动.其实未启动成功: [root ...

  8. 解决浏览器自动填充input

    浏览器输入框自动填充解决办法 emmmmm:今天处理公司后台系统遇到的:登录页面浏览器保存账号密码后:浏览器会自动在其他页面进行填充:解决如下图: 浏览器会默认填充input type值为passwo ...

  9. Ubuntu下压缩与解压各种文件的命令

    1.压缩与解压xz文件 (1)压缩 xz -z  filename (2)解压 xz -d  filename.xz 2.压缩与解压tar文件 (1)压缩 tar -cvf  filename(压缩到 ...

  10. Cookie 详解以及实现一个 cookie 操作库

    Cookie 详解以及实现一个 cookie 操作库 cookie 在前端有着大量的应用,但有时我们对它还是一知半解.下面来看看它的一些具体的用法 Set-Cookie 服务器通过设置响应头来设置客户 ...