先簡單說一下spring cloud的配置中心的一些概念git
Spring-cloud Config Server 有多種種配置方式,github
一、config 默認Git加載
經過spring.cloud.config.server.git.uri指定配置信息存儲的git地址,好比:https://github.com/xxx/config-repospring
二、加載本地開發環境
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config
因此我如今的配置大體以下(yml)windows
spring:
application:
name: config-center
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/configs/{profile}
# searchLocations: file:/d:/configs/{profile}
git:
uri: https://xx.com/xxx/cloud-service-configs.git
default-label: master
force-pull: true
searchPaths: '{profile}'
由於配置了active: native,因此這裏是使用本地配置的app
咱們這裏有一個configs.dev的目錄ide
而具體的微服務須要作以下配置來獲取dev目錄下的配置(以productprovider微服務爲例)微服務
spring: application: name: productprovider cloud: config: discovery: enabled: true serviceId: config-center profile: dev
要進行多環境配置,好比咱們要創建一個local的配置spa
若是咱們這樣創建一個文件夾的話3d
其結果是真的創建了一個configs.local的單一文件夾,而不是在configs文件夾下面創建一個local文件夾。server
在這裏windows,mac下面的狀況都同樣,因此正確的作法是進入configs目錄下,手工創建一個local的文件夾(windows請在資源管理器下操做)
將你須要的配置文件拷貝到該local目錄下進行修改,再修改要啓動的微服務的配置
spring: application: name: productprovider cloud: config: discovery: enabled: true serviceId: config-center # profile: dev profile: local
就能夠在多配置環境下使用配置中心了。