Spring源码(3)Context篇之ConfigurableWebApplicationContext

本文深入探讨Spring的Context篇章,聚焦ConfigurableWebApplicationContext接口及其在WebApplicationContext、XmlWebApplicationContext中的应用。通过源码分析,揭示了contextConfigLocation在web.xml中的配置以及在启动过程中的作用,详细阐述了上下文刷新的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇讲解了Spring通过ContextLoader类的initWebApplicationContext方法创建的WebApplicationContext实为XmlWebApplicationContext实例

再看initWebApplicationContext方法的源码:

/**
 *  为了讲重点,省略了部分源码
 */
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
   
   
 	...
	try {
   
   
		// Store context in local instance variable, to guarantee that
		// it is available on ServletContext shutdown.
		if (this.context == null) {
   
   
			this.context = createWebApplicationContext(servletContext);		//312行
		}
		if (this.context instanceof ConfigurableWebApplicationContext) {
   
   		//314行
			//重点就是这里的ConfigurableWebApplicationContext
			ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
			if (!cwac.isActive()) {
   
   
				// The context has not yet been refreshed -> provide services such as
				// setting the parent context, setting the application context id, etc
				if (cwac.getParent() == null) {
   
   
					// The context instance was injected without an explicit parent ->
					// determine parent for root web application context, if any.
					ApplicationContext parent = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值