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 }
原文地址:https://www.cnblogs.com/yszzu/p/9948742.html
时间: 2024-11-08 19:40:47