初学Spring源码3.1:prepareRefresh()

/**
 * 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,用于存储早期的应用时间,以便在事件广播组可用时进行发布
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值