三、springboot 配置文件加載順序
文件分類
-
按文件名分類
可以分爲 bootstrap 和 application -
按後綴名分類
可以分爲yml 和properties 當然這裏還有一個 yaml 它其實與yml 是同一個東西,yml是 yaml 更簡單的寫法。所以我們肯定本着更簡單原則了。
bootstrap 文件比 application 文件先加載
bootstrap 文件加載順序
-
bootstrap.yaml
-
bootstrap.yml
-
bootstrap.properties
application 加載順序
-
application.yaml
-
application.yml
-
application.properties
如何驗證?
當然是起個項目給每個文件配置個端口如下
properties
server.port=8080
yml
server:
port: 8081
當然你也可以從啓動類一步步跟進去,用簡單的方法就能驗證的咱就不用那麼複雜了。
總結:就一句話
bootstrap 比 application 先加載,而 yml 比 properties 先加載。
配置中心
如果我們的應用中加了配置中心,那麼配置中心的配置加載時機又是在什麼時候呢?這個得根據配置不同配置中心的配置切入點在什麼地方。此處我們按下不表,後續會有專門文章將配置中心。