spring的启动和关闭是通过在web.xml中注册启动监听器org.springframework.web.context.ContextLoaderListener来实现的,该类实现了接口javax.servlet.ServletContextListener。伴随web容器的启动和关闭,管理Spring的根org.springframework.web.context.WebApplicationContext。
该类本身并没有实现太多的代码,只是一个到org.springframework.web.context.ContextLoader和org.springframework.web.context.ContextCleanupListener的简单代理。
如果在web.xml中配置了org.springframework.web.util.Log4jConfigListener,则该监听器必须配置在它的后面。在spring3.1之后,如果在Servlet 3.0以上环境,ContextLoaderListener支持通过ContextLoaderListener(WebApplicationContext)构造器,以编码的方式来注入web应用的根上下文,而不用再在web.xml中进行配置。
当ContextLoaderListener在进行实例化的时候,会读取web.xml中配置的两个context-param参数:“contextClass“、“contextConfigLocation”。
ContextLoaderListener实例化之后,将会被注册到ServletContext的WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE属性上。
在Servlet3.0+环境中,使用ContextLoaderListener(WebApplicationContext)构造器,以编码的方式(非web.xml配置方式)通过javax.servlet.ServletContext.addListener接口注册该实例,如果context实例同时满足:实现ConfigurableWebApplicationContext接口、尚未刷新,将会产生以下操作:
- 如果context还没有id,将通过setId接口赋予id;
- ServletContext、ServletConfig将被代理到context;
- customizeContext方法将被调用;
- 所有通过contextInitializerClasses初始化参数配置的 ApplicationContextInitializer接口实现都将被应用;
- 调用refresh接口;
如果context实例已经刷新或者没有实现ConfigurableWebApplicationContext接口,以上操作不会自动发生,需要用户根据自己的需用自行调用。
相关推荐
Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动完整流程图 Spring启动...
beetl-spring-boot-starter,beetl 自动配置 Spring 启动。使用:从 maven 导入该库 <groupId>com.piggsoft</groupId> <artifactId>beetl-spring-boot-starter <version>0.0.1 配置 application....
spring启动.txt 详细介绍Spring 在tomcat容器里的启动过程
使用vision画的spring启动流程图,详细介绍了spring从tomcat启动到创建初始化根上下文的过程。
spring配置和启动方式 博客地址:https://blog.csdn.net/u010476739/article/details/76696756
spring 启动时根据配置文件的不同加载不同的文件
14、加载spring启动首先进入的类方法注解1
spring容器启动和关闭时事件监听;spring容器启动和关闭时事件监听;spring容器启动和关闭时事件监听
spring启动componentscan类扫描加载过程—源码分析Java开发Java经验技巧共16页.pdf.zip
Spring启动Tomcat的https和http双端口的案例
spring启动过程代码级别描述,.......上传为了方便自己日后复习
Spring启动时间表
1. Spring容器的启动流程 2. 循环依赖 3. Spring 中Bean的创建 4. Spring 方法xmind脑图
主要介绍了Spring启动后获取所有拥有特定注解的Bean实例代码,分享了相关代码示例,小编觉得还是挺不错的,具有一定借鉴价值,需要的朋友可以参考下
demo spring 3.0 mvc
AbstractApplicationContext.refresh(){ 1.为刷新准备此上下文 prepareRefresh(){ initPropertySources();//在上下文环境中初始化任何占位符属性源 getEnvironment().validateRequiredProperties();...
没有建立起稳定、规范的IT运维机制。现有的IT运维流程的操作层面缺乏统一。如事件单提交之后,事件预判和优先级的设定缺少统一、规范的指导文档,仅以人员的主观经验或约定俗成的方式指导事件的处理过程。...
NULL 博文链接:https://linlargy.iteye.com/blog/1846991
Spring引导项目中的Apache骆驼入门这个项目是关于在Spring启动项目中使用Apache camel创建API。正在安装该项目用Spring boot实现。 您可以通过以下方法运行该项目。 作为打包的应用程序运行。 java -jar target/demo...
spring 源码解析