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. Javaweb学习笔记4—Reuest&Response

    今天来讲javaweb的第四段学习. Request和Response还是比较重要的 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思维是用的xMind画的,如果你对我的思维导图感兴趣 ...

  2. postgres的强制类型转换与时间函数

    一.类型转换postgres的类型转换:通常::用来做类型转换,timestamp到date用的比较多select  now()::dateselect  now()::varchar 示例1:日期的 ...

  3. JVM的异常体系

    任何程序都追求正确有效的运行,除了保证我们代码尽可能的少出错之外,我们还要考虑如何有效的处理异常,一个良好的异常框架对于系统来说是至关重要的.最近在采集框架的时候系统的了解一边,收获颇多,特此记录相关 ...

  4. Vue之组件的生命周期

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. JavaScript递归简单实现个对象深拷贝

    JavaScript中对象的深拷贝来说一直都算比较恶心 毕竟没有什么api能直接全拷贝了 得自己便利写  最近在项目中需要深拷贝 自己简单封了个方法 话不多说 直接上码 <!DOCTYPE ht ...

  6. JS简单实现防抖和节流

    一.什么是防抖和节流 Ps: 比如搜索框,用户在输入的时候使用change事件去调用搜索,如果用户每一次输入都去搜索的话,那得消耗多大的服务器资源,即使你的服务器资源很强大,也不带这么玩的. 1. 防 ...

  7. 配置c3p0-config.xml数据库连接池,jdbcurl配置项报错Type The reference to entity "useUnicode" must end with the ';' delimiter.

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xml> <c3p0-confi ...

  8. linux系统日志中出现大量systemd Starting Session ### of user root 解决

    这种情况是正常的,不算是一个问题 https://access.redhat.com/solutions/1564823 Environment Red Hat Enterprise Linux 7 ...

  9. 由Java实现Valid Parentheses

    一.题目 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

  10. 【HIHOCODER 1575】 两个机器人(BFS)

    描述 一个N × M的2D迷宫中有两个机器人.机器人A在迷宫左上角,只能向右或向下移动:机器人B在迷宫右下角,只能向左或向上移动.机器人不能移动到迷宫外.此外,由于奇怪的同步机制,这两个机器人只能同时 ...