1. 若application.yml 和bootStrap.yml 在同一目錄下,則bootStrap.yml 的加載順序要高於application.yml,即bootStrap.yml 會優先被加載。java
原理:bootstrap.yml 用於應用程序上下文的引導階段。git
bootstrap.yml 由父Spring ApplicationContext加載。spring
•bootstrap.yml 能夠理解成系統級別的一些參數配置,這些參數通常是不會變更的。
•application.yml 能夠用來定義應用級別的,若是搭配 spring-cloud-config 使用 application.yml 裏面定義的文件能夠實現動態替換。bootstrap
2. 不一樣位置的配置文件的加載順序:服務器
在不指定要被加載文件時,默認的加載順序:由裏向外加載,因此最外層的最後被加載,會覆蓋裏層的屬性(參考官網介紹)app
SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment: ide
A /config subdirectory of the current directory. //位於與jar包同級目錄下的config文件夾,
The current directory //位於與jar包同級目錄下
A classpath /config package //idea 環境下,resource文件夾下的config文件夾
The classpath root //idea 環境下,resource文件夾下 (1->4, 外->裏)
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).url
3. 能夠經過屬性指定加載某一文件:idea
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
當經過spring.config.location 指定一個配置文件時,配置文件的搜索順序以下:spa
file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/
最下層的優先加載,因此最上層的屬性會覆蓋下層的屬性;
4. 若是使用spring-cloud-config時,項目內部的resource下有bootstrap.yml文件,而且在bootstrap.yml 裏配置spring.application.name, git.url,spring.active.profies. 將項目打成jar包,放到服務器上,與jar包並列的位置,有start.sh腳本,
a. 在start 腳本里指定了配置文件:spring.config.location=./bootstrap.yml, 則配置文件的加載順序將爲:
1. cloud-config 倉庫裏指定的yml 配置;
2. ./bootstrap.yml
3. classpath:/bootstrap.yml
4. 外部application.yml
5. 內部application.yml
b. 在start 腳本里指定了配置文件:spring.config.location=./application.yml, 則配置文件的加載順序將爲:
1. cloud-config 倉庫裏指定的yml 配置;
2. ./application.yml
3. classpath:/application.yml
4. ./bootstrap.yml
5. classpath:/bootstrap.yml
因此,無論是jar包內仍是jar運行的同級目錄下,只要包含bootstrap.yml ,且爲雲配置,則雲配置文件會覆蓋其餘配置文件;