Spring Cloud會將配置映射爲"/{application}/{profile}"
URL地址和資源文件映射如下:
- /{application}/{profile}[/{label}]
- /{application}-{profile}.yml
- /{label}/{application}-{profile}.yml
- /{application}-{profile}.properties
- /{label}/{application}-{profile}.properties
-
注意:
- 第一個規則的分支名是可以省略的,默認是master分支
- 無論你的配置文件是properties,還是yml,只要是應用名+環境名能匹配到這個配置文件,那麼就能取到
- 如果是想直接定位到沒有寫環境名的默認配置,那麼就可以使用default去匹配沒有環境名的配置文件
- 使用第一個規則會匹配到默認配置
- 如果直接使用應用名來匹配,會出現404錯誤,此時可以加上分支名匹配到默認配置文件
- 如果配置文件的命名很由多個-分隔,此時直接使用這個文件名去匹配的話,會出現直接將內容以源配置文件內容直接返回,內容前可能會有默認配置文件的內容
- 如果文件名含有多個“-”,則以最後一個“-”分割{application}和{profile},若文件名爲:my-app-demo-dev.properties,則映射的url爲"/my-app-demo/dev"
示例:資源文件爲myapp-dev.properties,對應url爲:http://xxx/myapp/dev
客戶端配置:
spring.application.name=xxxx
spring.cloud.config.profile=dev
spring.cloud.config.label=test
上述配置與資源文件對應關係爲:
spring.application.name對應{application}
spring.cloud.config.profile對應{profile}
spring.cloud.config.label對應{label}