springboot啟動配置載入順序問題

2021-10-01 12:57:55 字數 3929 閱讀 7935

springboot啟動之後,

}第一行獲取

@functionalinte***ce

public

inte***ce

environmentpostprocessor

接下來就開始執行environmentpostprocessor

public

void

load()

<

----

----

----

----

----

---↓↓↓--

----

----

----

----

----

->

this

.load

(this

::getnegativeprofilefilter,

this

.addtoloaded

(mutablepropertysources:

:addfirst,

true))

;<

----

----

----

----

----

---↑↑↑--

----

----

----

----

----

->

this

.addloadedpropertysources()

;}

public

void

load()

<

----

----

----

----

----

---↓↓↓--

----

----

----

----

----

->

this

.load

(this

::getnegativeprofilefilter,

this

.addtoloaded

(mutablepropertysources:

:addfirst,

true))

;this

.addloadedpropertysources()

;<

----

----

----

----

----

---↑↑↑--

----

----

----

----

----

->

}

擴充套件:

在遍歷配置檔案的時候會按照如下規則進行查詢

private set

getsearchlocations()

else

}

至此本地的環境變數,配置檔案已經讀取完畢了,不過配置還缺少一步就是當我們用到配置中心的時候還需要執行如下操作,這裡我們以apollo為例進行簡單的說明。這個時候前面提到的initializers就派上用場了。看**

(string.

.. args)

, context)

;<

----

----

----

----

----

---↓↓↓--

----

----

----

----

----

->

this

.preparecontext

;<

----

----

----

----

----

---↑↑↑--

----

----

----

----

----

->

this

.refreshcontext

(context)

;this

.afterrefresh

; stopwatch.

stop()

;if(this

.logstartupinfo)

listeners.

started

(context)

;this

.callrunners;}

catch

(throwable var9)

listeners.

running

(context)

;return context;

}

private

void

preparecontext

context.

getbeanfactory()

.registersingleton(;

if(printedbanner != null)

setsources =

this

.getallsources()

; assert.

notempty

(sources,

"sources must not be empty");

this

.load

(context, sources.

toarray

(new

object[0

]));

listeners.

contextloaded

(context)

;}

-------------------------------->拋磚引玉

SpringBoot加https的配置

1.訂單號.pfx 2.訂單號.pem 3.訂單號.keykeytool importkeystore srckeystore 訂單號.pfx destkeystore 訂單號.jks srcstoretype pkcs12 deststoretype jks注 首先需要設定兩次目標金鑰的密碼,然後...

Spring Boot啟動配置原理

run 列印banner資訊 建立ioc容器物件 run 重新整理啟動ioc容器 掃瞄載入所有容器中的元件 包括從meta inf spring.factories中獲取的所有enableautoconfiguration元件 配置在meta inf spring.factories command...

SpringBoot啟動配置原理

springboot應用啟動,呼叫此方法 return run new object args 初始化 initialize sources private void initialize object sources 當前應用是否是web應用 this.webenvironment deducew...