spring cloud config配置中心總結篇+從本地獲取配置檔案
1、配置中心就是一個spring boot專案 ,可以直接暴露url 讓其它微服務獲取配置,也可以註冊到eureka註冊中心,其它微服務從註冊中心獲取配置
2、配置中心可以從git、本地、svn獲取配置檔案 ,這三個地方的檔名字,採用{application}-{profile}.yml 或者{application}-{profiles}.properties 例如web-dev.properties jobServices-test.yml
{profile} 分為dev test prod 預設(就是什麼也不加 例如 web.properties) 開發、測試、產品四個級別
{application} 這個和微服務的名字對應 除了配置中心和註冊中心的,其它微服務配置的spring.application.name對應就是這個
spring.cloud.config.profile 配置的對應著 {profile}
3、本地配置檔名字的前半部分,和需要它的微服務的名字一樣,後半部分由開發 測試 等等構成 或者預設的不寫
下面貼出 使用本地配置檔案;
4、註冊中心優先於配置中心啟動,所以不需要從配置獲取檔案
5、配置中心預設獲取git下的 master分支,當然分支 、git下的路徑都可以配置的
config-server 端
config-client 端
spring:
application:
name: jobservice #該名字就是本地配置檔案的字首,也是註冊到註冊中心服務名稱
cloud:
config:
profile: test #該名字就是本地配置檔案的-dev -test這些 如果是default 配置檔名字為 web.propertie 沒有dev部分了
discovery:
enabled: true
service-id: configserver
server:
port: 9190
eureka:
client:
service-url:
defaultZone: http://discovery:8761/eureka/