深入理解Spring源码(一)之prepareRefresh()方法

开篇我们已经开门见山 引入了sping容器初始化整个过程将经历12个历程 下面我们来介绍漫漫长征路的第一个方法





prepareRefresh();    //准备工作  初始化spring状态 使spring处于运行状态

 

我们进入方法体

protected void prepareRefresh() {
		// Switch to active
		//纪录启动时间
		this.startupDate = System.currentTimeMillis();
		System.out.println("spring启动时间为--------------------" + this.startupDate);
		this.closed.set(false);
		System.out.println("spring标记为未关闭--------------------" + this.closed);
		this.active.set(true);
		System.out.println("spring当前激活状态--------------------" + this.active);

		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
		//校验 xml配置文件
		getEnvironment().validateRequiredProperties();

		// Store pre-refresh ApplicationListeners...
		//初始化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<>();
	}

这个方法我们只是负责将spring容器设置相应的状态 并且校验xml

我们暂且跳过 接下来我们看看 obtainFreshBeanFactory()方法 这个是bean的准备工作的核心!

 

下一篇:将介绍obtainFreshBeanFactory()方法 

详情请看 https://blog.csdn.net/spring_live_in/article/details/101059038

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值