/**
* Prepare this context for refreshing, setting its startup date and
* active flag as well as performing any initialization of property sources.
*/
protected void prepareRefresh() {
// Switch to active.
//记录初始化时间
this.startupDate = System.currentTimeMillis();
//context是否关闭标志 false
this.closed.set(false);
//context是否激活的状态 true
this.active.set(true);
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
// 校验所有必须的属性是否已经加载
// 而所有必须的属性是调用ConfigurablePropertyResolver.setRequiredProperties()方法添加的属性
getEnvironment().validateRequiredProperties();
// Store pre-refresh ApplicationListeners...
// 创建一个set,存储刷新之前的一些应用监听器
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...
// 创建一个set,用于收集一些早期的应用事件,在事件广播组可用时进行发布
this.earlyApplicationEvents = new LinkedHashSet<>();
}
- 记录初始化时间
- 设置上下文close和active的标志
- 校验环境和必须的属性
- 创建一个LinkedHashSet用于存放刷新前的应用监听器
- 创建一个LinkedHashSet,用于存储早期的应用时间,以便在事件广播组可用时进行发布