spring启动时加载ContextLoaderListener监听器

这几天有点空闲时间,研究了下spring启动时监听器的加载过程。

我们知道当servlet容器启动或者加载的时候会触发ServletContextEvent事件,监听器进行初始化或者销毁。

其中createContextLoader()方法都是返回null,直接赋值

然后通过this.contextLoader.initWebApplicationContext(event.getServletContext())来进行其他的操作

其中ApplicationContext parent = loadParentContext(servletContext)这个方法主要是用来解决spring的共享问题的。此处如何解决共享问题暂时还未研究(待下次再继续研究)

this.context = createWebApplicationContext(servletContext, parent)实现了WebApplicationContext的创建,此方法创建了org.springframework.web.context.support.XmlWebApplicationContext实例,通过读取(

org/springframework/web/context/ContextLoader.properties)文件中的信息来确定实例对象的;

最后,spring加载完成之前,会将aplicationContext放入到servletContext中

当我们启动时,就会判断我们的服务是否已经启动

只是比较浅的研究啦一下,以后会继续深入的研究

 

posted @ 2015-10-29 16:17  不穿格子衫的猿  阅读(1302)  评论(0编辑  收藏  举报