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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章