使用到的組件如下
| Cloud Config | 
|---|
| Config Server | 
主要依賴是 spring-cloud-config-server
dependencies {
    compile('org.springframework.cloud:spring-cloud-config-server')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}
application.properties
spring.cloud.config.server.git.uri=D:/springcloud/config-repo
server.port=8888
server.port: ${PORT:${SERVER_PORT:0}}
info.id: ${spring.application.name}
debug: true
spring.sleuth.log.json.enabled: true
logging.pattern.console: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex"
reservation-service.properties
server.port=${PORT:8000}
message=HELLO world!
spring.cloud.stream.bindings.input=reservations
起動程式
ConfigServerApplication.java
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
記得加上@EnableConfigServer就可以啟動ConfigServer的功能了
起動 Config-Server 後可以訪問 http://localhost:8888/reservation-service/master 就可以取得設定相關資料
{
  "name": "reservation-service",
  "profiles": [
    "master"
  ],
  "label": null,
  "version": "b017cbcb47700df4ffd7e824614532dd18128040",
  "propertySources": [
    {
      "name": "D:/springcloud/config-repo/reservation-service.properties",
      "source": {
        "server.port": "${PORT:8000}",
        "spring.cloud.stream.bindings.input": "reservations",
        "message": "HELLO world!"
      }
    },
    {
      "name": "D:/springcloud/config-repo/application.yml",
      "source": {
        "server.port": "${PORT:${SERVER_PORT:0}}",
        "info.id": "${spring.application.name}",
        "debug": true,
        "spring.sleuth.log.json.enabled": true,
        "logging.pattern.console": "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex"
      }
    }
  ]
}