Spring容器刷新之prepareRefresh

prepareRefresh是容器刷新的第一步,过程比较简单,直接看中文注释。

	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.
		//模版方法,通常在web环境下使用,可以将ServletContext、ServletConfig等记录在运行时环境变量中。
		initPropertySources();

		// Validate that all properties marked as required are resolvable:
		// see 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,
		// to be published once the multicaster is available...
		//用来存放在事件派发器初始化前就产生的事件
		this.earlyApplicationEvents = new LinkedHashSet<>();
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值