zoukankan      html  css  js  c++  java
  • SpringCloud分布式配置中心

    一、什么是配置中心

      在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在spring cloud config 组件中,分两个角色,一是config server,二是config client。

    二、创建git地址

      1、使用码云创建git地址 https://gitee.com

      2、config-client-dev.properties  ---dev环境

        

      3、上传配置文件到码云仓库

        

     三、查询配置中心http://localhost:8000/foo/dev

      1、目录展示

        

       2、导入依赖  

    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
    
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
      </dependencies>
      <dependencyManagement>
        <dependencies>
          <!--springCloud依赖-->
          <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
    
        </dependencies>
      </dependencyManagement>

      3、application.properties配置文件

            

        spring.cloud.config.server.git.uri:配置git仓库地址

        

        spring.cloud.config.server.git.searchPaths:配置仓库路径

        spring.cloud.config.label:配置仓库的分支

        spring.cloud.config.server.git.username:访问git仓库的用户名

        spring.cloud.config.server.git.password:访问git仓库的用户密码

      4、StartSpringCloudConfig启动类

        

       5、访问配置中心

        

     四、创建config-client项目

      1、目录展示

        

       2、导入依赖

    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
      </dependencies>
      <dependencyManagement>
        <dependencies>
          <!--springCloud依赖-->
          <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
    
        </dependencies>
      </dependencyManagement>

      3、bootstrap.properties配置文件

        

       4、ConfigClientController

          

        

      5、StartConfigClient启动类    

    package com.zn;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class StartConfigClient {
        public static void main(String[] args) {
            SpringApplication.run(StartConfigClient.class,args);
        }
    }

       6、效果展示

         

        

  • 相关阅读:
    Android应用程序执行流程
    Android的架构与Android应用程序启动流程
    Android开发环境使用工具Eclipse IDE工程目录结构
    MySQL 的 crash-safe 原理解析
    vivo 悟空活动中台
    图解 Promise 实现原理(三)—— Promise 原型方法实现
    领域驱动设计(DDD)实践之路(三):如何设计聚合
    深入浅出开源监控系统Prometheus(上)
    你还应该知道的哈希冲突解决策略
    反应式编程 RxJava 设计原理解析
  • 原文地址:https://www.cnblogs.com/Zzzzn/p/12077624.html
Copyright © 2011-2022 走看看