第三章:Spring Cloud Config Server 的配置

1.为什么要使用config

  1. 集中管理
  2. 不通环境不通配置
  3. 运行期间动态调整配置
  4. 自动刷新

2.用法入门

  1. 导入pom
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
  1. 启动类添加注解
    @EnableConfigServer
  2. 修改application.yml
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/jiaofanting/spring-cloud-config-repo/
server:
  port: 8080

这个uri是我git目录放的一个application.yml 路径,打开是404,因为它不是一个有效的链接,它只是说明了 application.yml文件放在哪里。

  1. 看官方文档说明
The HTTP service has resources in the form:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

where the "application" is injected as the spring.config.name in the SpringApplication (i.e. what is normally "application" in a regular Spring Boot app), "profile" is an active profile (or comma-separated list of properties), and "label" is an optional git label (**defaults to "master".**)

截图更清晰



注意中间有个- ,对照文档看效果


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,915评论 18 139
  • 介绍 分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spr...
    RalapHao阅读 1,428评论 0 2
  • 1. git仓库中配置文件的名字是有作用的 比如utaha-dev.yml,代表了{application}-{...
    Kitsuna阅读 1,873评论 0 0
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,950评论 6 342
  • 概述:springcloud-config是一个利用git.svn等进行微服务的分布式配中心的东西,既然sprin...
    白敏鸢阅读 641评论 0 0