且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

第十二章:Spring Cloud Config Server 的配置

更新时间:2022-07-18 10:42:25

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".**)

截图更清晰


第十二章:Spring Cloud Config Server 的配置

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


第十二章:Spring Cloud Config Server 的配置
image.png