开篇我们已经开门见山 引入了sping容器初始化整个过程将经历12个历程 下面我们来介绍漫漫长征路的第一个方法
prepareRefresh(); //准备工作 初始化spring状态 使spring处于运行状态
我们进入方法体
protected void prepareRefresh() {
// Switch to active
//纪录启动时间
this.startupDate = System.currentTimeMillis();
System.out.println("spring启动时间为--------------------" + this.startupDate);
this.closed.set(false);
System.out.println("spring标记为未关闭--------------------" + this.closed);
this.active.set(true);
System.out.println("spring当前激活状态--------------------" + this.active);
if (logger.isDebugEnabled()) {
if (logger.isTraceEnabled()) {
logger.trace("Refreshing " + this);
} else {
logger.debug("Refreshing " + getDisplayName());
}
}
// Initialize any placeholder property sources in the context environment.
//我们点进去发现没有做任何事情
initPropertySources();
// Validate that all properties marked as required are resolvable:
// see ConfigurablePropertyResolver#setRequiredProperties
//校验 xml配置文件
getEnvironment().validateRequiredProperties();
// Store pre-refresh ApplicationListeners...
//初始化applicationListeners监听容器
if (this.earlyApplicationListeners == null) {
this.earlyApplicationListeners = new LinkedHashSet<> (this.applicationListeners);
} else {
// Reset local application listeners to pre-refresh state.
this.applicationListeners.clear();
this.applicationListeners.addAll(this.earlyApplicationListeners);
}
// Allow for the collection of early ApplicationEvents,
// to be published once the multicaster is available...
this.earlyApplicationEvents = new LinkedHashSet<>();
}
这个方法我们只是负责将spring容器设置相应的状态 并且校验xml
我们暂且跳过 接下来我们看看 obtainFreshBeanFactory()方法 这个是bean的准备工作的核心!
下一篇:将介绍obtainFreshBeanFactory()方法
详情请看 https://blog.csdn.net/spring_live_in/article/details/101059038