Spring源码情操陶冶-AbstractApplicationContext#prepareRefresh

时间:2022-10-01 03:07:19

前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext

约束:

  1. 本文指定contextClass为默认的XmlWebApplicationContext
  2. 从属AbstractApplicationContext#refresh方法

AbstractApplicationContext#prepareRefresh

代码清单如下

protected void prepareRefresh() {
//设置刷新开始时间
this.startupDate = System.currentTimeMillis(); //设置ApplicationContext的激活状态为true
synchronized (this.activeMonitor) {
this.active = true;
} if (logger.isInfoEnabled()) {
logger.info("Refreshing " + this);
} // Initialize any placeholder property sources in the context environment
initPropertySources(); // Validate that all properties marked as required are resolvable
// see ConfigurablePropertyResolver#setRequiredProperties
getEnvironment().validateRequiredProperties();
}

如官方注释所示,上述预刷新方法主要是设置refresh操作的起始时间、active=true、并且初始化属性资源的校验(此处可忽略,无任何操作)

下节预告

Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory