/** * Prepare this context for refreshing, setting its startup date and * active flag as well as performing any initialization of property sources. */ protectedvoidprepareRefresh(){ //开始时间 this.startupDate = System.currentTimeMillis(); this.closed.set(false); this.active.set(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 //得到环境信息,默认的是StandardEnvironment。然后来验证一些必要的属性是否存在,如果不存在,那么此处就会 //抛出异常 //StandardEnvironment用的是委托模式,validateRequiredProperties的时候委托给了自己内部的属性解析器,也就是 //propertyResolver。 //propertyResolver在实例化的时候,会接收属性源,解析器的父类有一个私有集合对象用于储存key; //validate的时候,会通过解析器的getProperty取值然后验证是否存在; 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, // to be published once the multicaster is available... this.earlyApplicationEvents = new LinkedHashSet<>(); }