SpringWeb ContextLoaderListener 初始化过程

ContextLoaderListener extends ContextLoader implements ServletContextListener

WebApplicationContext初始化的代码逻辑在ContextLoader中,供实现ServletContextListener接口的contextInitialized和contextDestroyed方法调用

初始化:ContextLoaderListener.contextInitialized -> ContextLoader.initWebApplicationContext(ServletContext)

initWebApplicationContext: 

1. 检查web容器中是否存在同名(attrName,定义见5)的WebApplicationContext,若存在则报错(通常若在web.xml中定义了多个ContextLoaderListener,则必然存在)

2. 调用createWebApplicationContext创建新的WebApplicationContext context

3. 若context的parent为null,调用loadParentContext从web容器中检查是否存在外部的父ApplicationContext(通常不存在),并获取,设置为context的parent

4. 调用ContextLoader.configureAndRefreshWebApplicationContext

4.1. 设置context的各项配置和环境参数

4.2. 调用customizeContext,用于处理一些自定义的代码

4.3. context.refresh()

5. 调用ServletContext.setAttribute将context注册到web容器中,attrName为org.springframework.web.context.WebApplicationContext.ROOT

6. 处理ClassLoader与context的映射关系

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值