zoukankan      html  css  js  c++  java
  • SpringCloud------配置中心Config

    1.

     什么是配置中心

      统一管理配置,怏速切换各个环境的配置


    相关产品:
    百度的 discont
      https://github.com/knightliao/disconf
    阿里的diamand
      https://github.com/takeseem/diamond
    springcloud的configs-server:
      http://cloud.spring.io/spring-cloud-config/

    推荐文章

      http://jm.taobao.org/2016/09/28/an-article-about-config-center/

    2.添加依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    3.启动类添加注解@EnableConfigServer

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.config.server.EnableConfigServer;
    
    @SpringBootApplication
    @EnableConfigServer
    public class ConfigServiceApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ConfigServiceApplication.class, args);
        }
    
    }

    4.修改application.yml配置

    server:
      port: 9100
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    
    spring:
      application:
        name: config-server
      cloud:
        config:
          server:
            git:
              #仓库地址,去掉git
              uri: https://gitee.com/YTHeng/config_cloud
              #git服务器登录的用户名和密码,我这边使用的是码云
              username: 12345678@qq.com
              password: 12345678.
              #超时时间
              timeout: 5
              #分支
              default-label: master

    5.在码云服务器新建仓库和文件

    6.访问地址

    http://localhost:9100/master/product-service-dev.yml

    路径访问方式

    /{name}-{profiles}. properties
    /{name}-{profiles}.yml
    /{name}-{profiles}.json
    /{label}/{name]-{profiles].yml


    name:服务器名称
    profile:环境名称,开发、测试、生产
    Lable:仓库分支、默认 master分支

    另附:

  • 相关阅读:
    ASP.NET 取得 Request URL 的各个部分
    将GAC中的DLL复制出来
    SqlServer2008 手动提交
    SQL获取表中最新插入的记录
    HTTP/1.1 500 Server Error错误解决方法
    ORACLE 物化视图
    JIMMY ZHANG告诉你快速提高自己的开发能力
    走进设计模式系列之开篇
    大话设计模式之:Adapter模式
    jquery+bootstrap自定义插件开发之dropdownlist
  • 原文地址:https://www.cnblogs.com/tianhengblogs/p/12507862.html
Copyright © 2011-2022 走看看