1. 程式人生 > >spring boot environment載入過程分析

spring boot environment載入過程分析

 

 environment是在printBanner之前就初始化好了, 更在context建立之前, 

已經載入application-xxxx.properties, System.properties, System.environment ...

也可以自己監聽應用啟動 SpringApplicationRunListener事件, 完成自己的獨特的配置載入方案

啟動後呼叫listener.finished() 列印一些啟動後的資訊

 

prepareEnvironment()原始碼如下
 1     private
ConfigurableEnvironment prepareEnvironment( 2 SpringApplicationRunListeners listeners, 3 ApplicationArguments applicationArguments) { 4 // Create and configure the environment 5 ConfigurableEnvironment environment = getOrCreateEnvironment(); 6 7 //載入標準目錄下的配置檔案 &profile
8 configureEnvironment(environment, applicationArguments.getSourceArgs()); 9 //載入自定義的配置方案 10 listeners.environmentPrepared(environment); 11 if (!this.webEnvironment) { 12 environment = new EnvironmentConverter(getClassLoader()) 13 .convertToStandardEnvironmentIfNecessary(environment);
14 } 15 return environment; 16 }