spring源码分析-应用启动过程

来源:互联网 发布:水果软件 编辑:程序博客网 时间:2024/05/17 04:22

我们从基于spring-mvc的web项目的启动和加载开始说起,服务器为tomcat

1.启动时 tomcat会读取web.xml,容器创建servletContext,核心参数<context-param>,其数据配置在配置文件中,通常叫做application.xml(spring的配置文件)
2.容器创建<listener>的实例,创建监听
核心listener  ContextLoaderListener
这个listener的主要功能是initWebApplicationContext(初始化spring的web上下文)
生成webApplicatinContext实例,默认是xmlWebApplicationContext
调用上下文的fresh方法,进行初始化
3.容器创建filter
4.容器创建serlvet
核心servlet   DispatcherServlet
它的核心参数context-param,其数据配置在配置文件中,通常叫做dispatcher-servlet.xml(spring mvc的配置文件),初始化过程中生成webApplicationContext实例

在这启动过程中我们看到一共有servletContext,spring的webApplicationContext,spring-mvc的webApplicationContext三个上下文
servletContext作为servlet容器上下文,提供宿主环境,spring的webApplicationContext为spring根上下文,spring-mvc的webApplicationContext为子上下文