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 }
@ConfigurationProperties 使用的變量也是從environment中取的
CLI參數配置方式:

參考:
