SpringCloud_config 分布式配置中心,与github通讯

1. 在github远程仓库上传一份配置文件,我的配置文件为application.yml

spring:
  profiles:
    active:
    - dev
---
spring:
  profiles: dev
  application:
    name: lgzservicecloud-config-lgz-dev-hello
---
spring:
  profiles: test
  application:
    name: lgzservicecloud-config-lgz-test

2. 在项目pom文件中加入如下依赖包

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>

3. 在项目的application.yml文件中配置,加入远程仓库,如下(这个是项目中的yml配置文件,根github上的不是同一个)

server:
  port: 8888

spring:
  application:
    name:  lgzservicecloud-config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xxxxx/xxxxx.git #GitHub上面的git仓库名字

4. 在application启动类上加开启configServer的注解

@EnableConfigServer

5. 启动服务并访问配置文件,有以下五种访问配置规则

  • {application}:配置文件的文件名
  • {profile}:读取的环境
  • {lable}:分支

/{application}/{profile}[/{lable}]

/{application}-{profile}.yml

/{lable}/{application}-{profile}.yml

/{application}-{profile}.properties

/{lable}/{application}-{profile}.properties

image

image

发布了45 篇原创文章 · 获赞 7 · 访问量 8298
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章