ContextLoaderListener加载过程(最详细版)
来源:互联网 发布:淘宝店有差评怎么办 编辑:程序博客网 时间:2024/06/05 18:25
以下描述,将是最详细版spring的ContextLoaderListener加载过程,没有之一。
ContextLoaderListener实现了ServletContextListener接口,ServletContextListener是Java EE标准接口之一,类似tomcat,jetty的java容器启动时便会触发该接口的contextInitialized。
1 顾,java容器启动触发ContextLoaderListener的contextInitialized
2 contextInitialized 方法调用ContextLoader的initWebApplicationContext方法。
3 initWebApplicationContext调用createWebApplicationContext方法
4 createWebApplicationContext 调用determineContextClass方法
5 determineContextClass有如下代码
contextClassName = defaultStrategies .getProperty(WebApplicationContext.class.getName());
显然是从defaultStrategies中加载的
ContextLoader 类中有段静态代码
static { try { ClassPathResource resource = new ClassPathResource( "ContextLoader.properties", ContextLoader.class); defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); } catch (IOException ex) { throw new IllegalStateException( "Could not load 'ContextLoader.properties': " + ex.getMessage()); } currentContextPerThread = new ConcurrentHashMap(1); }
ContextLoader.properties 文件内容如下:
org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext
至此,determineContextClass方法返回的是XmlWebApplicationContext
6 回到 initWebApplicationContext 方法,调用configureAndRefreshWebApplicationContext方法
7 configureAndRefreshWebApplicationContext 调用了AbstractApplicationContext的refresh方法
8 refresh 方法调用了obtainFreshBeanFactory
9 obtainFreshBeanFactory 调用了AbstractRefreshableApplicationContext类的refreshBeanFactory方法
10 refreshBeanFactory调用了XmlWebApplicationContext的loadBeanDefinitions
11 loadBeanDefinitions中加载了对应的applicationContext.xml
如果你还没看明白,请联系我。
- ContextLoaderListener加载过程(最详细版)
- 类加载的过程(详细)
- ContextLoaderListener(1)---WebApplicationContext创建过程
- SpringWeb ContextLoaderListener 初始化过程
- 读Spring的源代码三:ContextLoaderListener和DispatcherServlet的加载过程
- Spring MVC启动过程(1):ContextLoaderListener初始化
- Java中类的详细加载过程
- eclipse openRunDialog 查看详细加载过程
- VS2008最初级入门(包括建立项目的详细过程)
- 类的加载、连接与初始化过程的详细分析(上)
- 类的加载、连接与初始化过程的详细分析(中)
- 类的加载、连接与初始化过程的详细分析(下)
- 类的加载、连接与初始化过程的详细分析(上)
- 类的加载、连接与初始化过程的详细分析(中)
- 类的加载、连接与初始化过程的详细分析(下)
- 图片加载框架-Picasso最详细的使用指南
- 菜鸟之路——Spring MVC(十一)ContextLoaderListener加载配置文件
- 本地启动项目,提示web包未加载,ClassNotFound(如ContextLoaderListener)
- volley official https://github.com/google/volley
- java.lang.UnsupportedClassVersionError
- Centos7安装Mysql
- C语言 fread()与fwrite()函数说明与示例
- 11个Java 开源 socket框架
- ContextLoaderListener加载过程(最详细版)
- TensorFlow 入门 3 ——变量管理和模型持久化
- JDK动态代理笔记
- dubbo高级篇-13 Dubbo服务集群-集群容错模式
- java程序在JVM中的运行顺序:
- JavaScript语言基础
- 【NOIP2017提高组正式赛】Day1T3逛公园
- 1034. 有理数四则运算(20)
- 第一次考试