spring项目中,web.xml中的 ContextLoaderListener监听器的原理
来源:互联网 发布:网宿科技 阿里云 编辑:程序博客网 时间:2024/05/19 21:00
</pre><pre class="java" name="code">创建监听器和ServletContext的code:
</pre><pre class="java" name="code"><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext-*.xml</param-value> </context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
ContextLoaderListener的作用(一句话):初始化BeanFactory,并将BeanFactory设置到application中。
说明:
创建了ContextLoaderListener这个监听器,它继承了ContextLoader类、实现了ServletContextListener接口,监听器对Application的创建进行了监听 ;
有ServletContext创建了,这个事件就会被监听器的contextInitlized(ServletContext event)方法监听到;
将application设置到contextLoader属性上;
执行源码的this.contextLoader.initWebApplicationContext(event.getServletContext());
取出web.xml中contextConfigLocation参数的值,也就是spring的配置信息;
根据这些配置信息生成Bean工厂;
最后把这个bean工厂设置到application中去;
可以在后端处理器(Action)中通过application取出beanFactory,进而从beanFactory取出业务对象,进行业务操作。
--------------------------------------------------------------------------------
在spring、springMVC,项目中这种配置,具有通用性。
0 0
- spring项目中,web.xml中的 ContextLoaderListener监听器的原理
- [Spring]web.xml中配置ContextLoaderListener监听器的作用
- [Spring]web.xml中配置ContextLoaderListener监听器的作用
- ContextLoaderListener、RequestContextListener等web项目的监听器,用于实例化spring容器中的组件
- spring项目中监听器作用-ContextLoaderListener
- spring项目中监听器作用-ContextLoaderListener
- spring项目中监听器作用-ContextLoaderListener与Tomcat容器中的ServletContextListener
- web.xml文件中配置spring的ContextLoaderListener后报错
- web.xml中spring如何通过ContextLoaderListener初始化的
- 【随笔】Spring中的监听器ContextLoaderListener
- Spring :监听器ContextLoaderListener的作用
- Spring监听器ContextLoaderListener的作用
- spring监听器ContextLoaderListener的疑问
- Spring监听器ContextLoaderListener的作用
- Spring监听器ContextLoaderListener的作用
- Spring :监听器ContextLoaderListener的作用
- web.xml配置文件中ContextLoaderListener的作用
- Spring中的ContextLoaderListener(Web项目的起始节点)和ApplicationContextAware接口实现Spring工具类
- 树状数组各大经典博客初学整合
- cocos2d-js + webstrom 的安装与配置
- uuid udid区别
- golang windows下 调用外部程序隐藏cmd窗口
- Java classloader机制
- spring项目中,web.xml中的 ContextLoaderListener监听器的原理
- Uva1597 -Searching the Web
- NDK开发系列之环境的搭建
- 基于地图的短信追踪小练习(1)百度地图的初创建
- 欢迎使用CSDN-markdown编辑器
- Calendar 基本使用方式
- Java中IO总结
- vue.js入门实例
- 获取沙盒路径