继续点击refresh方法可以看到,Refresh the underlying {@link ApplicationContext}也就是刷新底层的ApplicationContext
继续跟进去,这里要选择AbstractApplicationContext
这里我们看一下AbstractApplicationContext的注释,注释内容
Abstract implementation of the {@link org.springframework.context.ApplicationContext} interface. Doesn't mandate the type of storage used for configuration; simply implements common context functionality. Uses the Template Method design pattern,requiring concrete subclasses to implement abstract methods.翻译过来就是当前抽象类是ApplicationContext接口的抽象实现,不强制要求用于配置的存储类型;它只是实现了公共上下文功能,使用的是模板方法的设计模式,需要具体的子类来实现抽象方法。下面我们再看refresh方法
refresh方法
/**
* 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();
this.closed.set(false);
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... 预刷新应用监听器
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, 允许收集早期的应用事件在multicaster可用后一次性发布
// to be published once the multicaster is available...
this.earlyApplicationEvents = new LinkedHashSet<>();
}
继续返回跟进refresh方法,在prepareRefresh之后是通知子类刷新内部bean工厂obtainFreshBeanFactory
obtainFreshBeanFactory