0061-Config Server搭建

旧城等待, 2023-07-25 06:11 42阅读 0赞

文章目录

        1. 前言
        1. git建立配置文件
        1. 搭建Config Server
        • 3.1 pom依赖
        • 3.2 yml配置
        • 3.3 主启动类
        1. git文件的访问方式

1. 前言

Config Server负责跟配置保存方通信例如git,将远程服务器上的配置克隆到本地。

2. git建立配置文件

springcloudconfig\shared目录下建立

  • config-client-dev.yml

    server:
    port: 9900
    foo: dev foo version

  • config-client-test.yml

    server:
    port: 9900
    foo: test foo version

新建release1.0分支
增加label参数,下为开发,测试一致

  1. server:
  2. port: 9900
  3. foo: dev foo version
  4. label: release1.0

3. 搭建Config Server

3.1 pom依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-config-server</artifactId>
  9. </dependency>
  10. </dependencies>

3.2 yml配置

  1. server:
  2. port: 9800
  3. spring:
  4. application:
  5. name: config-server
  6. cloud:
  7. config:
  8. server:
  9. git:
  10. uri: https://github.com/wenrongyao/springcloudconfig/
  11. search-paths: shared
  12. username: # 公共仓库可以不写
  13. password: # 公共仓库可以不写

3.3 主启动类

  1. @SpringBootApplication
  2. @EnableConfigServer
  3. public class ConfigServer9800Application {
  4. public static void main(String[] args) {
  5. SpringApplication.run(ConfigServer9800Application.class, args);
  6. }
  7. }

4. git文件的访问方式

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

用我们前面建立的两个配置文件来做说明:

  • config-client-dev.yml
  • config-client-test.yml

config-client指的是{application}部分

dev/test指的是{profile部分}

{label}值得是git的版本号

eg:下面两者都可以访问配置文件,当label不写时默认为master

http://localhost:9800/config-client/dev/release1.0

http://localhost:9800/release1.0/config-client-dev.yml

发表评论

表情:
评论列表 (有 0 条评论,42人围观)

还没有评论,来说两句吧...

相关阅读