SpringApplication
public ConfigurableApplicationContext run(String... args) {

ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments); //准备好了Environment,此刻Environment中都有哪些配置参数
configureIgnoreBeanInfo(environment);


}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, listeners);
throw new IllegalStateException(ex);
}

try {
listeners.running(context); //发布running中事件 ApplicationReadyEvent
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, null);
throw new IllegalStateException(ex);
}
return context; // 返回ok的ConfigurableApplicationContext
}


private ConfigurableEnvironment getOrCreateEnvironment() {
if (this.environment != null) {
return this.environment;
}
switch (this.webApplicationType) {
case SERVLET:
return new StandardServletEnvironment(); //servlet
case REACTIVE:
return new StandardReactiveWebEnvironment();
default:
return new StandardEnvironment();
}
}

AbstractEnvironment

public abstract class AbstractEnvironment implements ConfigurableEnvironment {

public AbstractEnvironment() {
customizePropertySources(this.propertySources); //子类覆盖
}

}


# 调用关系
# AbstractEnvironment 构造函数 -> StandardServletEnvironment.customizePropertySources -> StandardEnvironment.customizePropertySources

StandardServletEnvironment

public class StandardServletEnvironment extends StandardEnvironment implements ConfigurableWebEnvironment {

/** Servlet context init parameters property source name: {@value}. */
public static final String SERVLET_CONTEXT_PROPERTY_SOURCE_NAME = "servletContextInitParams";

/** Servlet config init parameters property source name: {@value}. */
public static final String SERVLET_CONFIG_PROPERTY_SOURCE_NAME = "servletConfigInitParams";

/** JNDI property source name: {@value}. */
public static final String JNDI_PROPERTY_SOURCE_NAME = "jndiProperties";



@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME)); //添加servletConfigInitParams propertysource
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); //添加servletContextInitParams propertysource
if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME)); //jndiProperties
}
super.customizePropertySources(propertySources); // 添加systemEnvironment systemProperties
}

}


StandardEnvironment 

public class StandardEnvironment extends AbstractEnvironment {

/** System environment property source name: {@value}. */
public static final String SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME = "systemEnvironment";

/** JVM system properties property source name: {@value}. */
public static final String SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME = "systemProperties";



@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
propertySources.addLast( //系统参数 (比如vm options)
new PropertiesPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties())); // addLast systemProperties
propertySources.addLast( // 环境变量
new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment())); // addLast systemEnvironment
}

}


spring源码之Environment_系统参数