zoukankan      html  css  js  c++  java
  • SpringCloudConfig

    方便服务配置文件统一管理,实时更新

    组成

    spring cloud config组件中,分两个角色,一是config server,二是config client

    Config Server是一个可横向扩展、集中式的配置服务器,它用于集中管理应用程序各个
    环境下的配置,默认使用Git存储配置文件内容,也可以使用SVN存储,或者是本地文件
    存储。

    Config ClientConfig Server的客户端,用于操作存储在Config Server中的配置内容。
    微服务在启动时会请求Config Server获取配置文件的内容,请求到后再启动容器

    配置中心微服务

    依赖
    
    <dependency>
        groupId>org.springframework.cloud</groupId>
        artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    
    启动类
    
    @SpringBootApplication
    @EnableConfigServer
    public class ConfigApplication {
    	public static void main(String[] args) {
    		SpringApplication.run(ConfigApplication.class, args);
    	}
    }
    
    application.yml
    
    server:
      port: 9998
    spring:
      application:
        name: tensquare‐config
      cloud:
        config:
          server:
            git:
              uri: https://gitee.com/ld/tensquare‐config.git
              basedir: E:Javaconfigasedir    #可以使用这个配置项来指定本地git仓库的路径
    
    #git的用户名
    spring.cloud.config.server.git.username=username
    #git的密码
    spring.cloud.config.server.git.password=password
    

    配置客户端

    依赖
    
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    
    bootstrap.yml
    
    spring:
      cloud:
        config:
            #/{label}/{name}-{profiles}.yml
            name: user    #一般以服务名来命名
            profile: dev    #一般作为环境标识,开发环境(dev)、测试环境(test)、生产环境(product)
            label: master
            uri: http://127.0.0.1:9998
    
    假如在不同环境下有很多共用的配置,我们可以再创建一个user.yml用来存放共同配置
    springcloud-config取配置时,会将你的对应环境配置与user.yml合并后再返回(前缀name相同)。
    
  • 相关阅读:
    python 连接sql server 解决中文乱码 及配置使用 web 服务使用
    Android调用.net的webservice服务器接收参数为空的情况
    好题推荐
    算法中一些trick和细节
    洛谷P2181 对角线
    新的开始
    文化课倒计时80天
    Electron-vue实现后台多进程(三. 自动化测试篇)
    工作感受月记202107月
    工作感受月记202106月
  • 原文地址:https://www.cnblogs.com/loveer/p/11441493.html
Copyright © 2011-2022 走看看