spring学习之ApplicationContext—— ContextLoaderListener和ContextLoaderServlet
来源:互联网 发布:淘宝章鱼家是真的吗 编辑:程序博客网 时间:2024/05/17 06:53
与BeanFactory通常以编程的方式被创建不同的是,ApplicationContext能以声明的方式创建,如使用ContextLoader。当然你也可以使用ApplicationContext的实现之一来以编程的方式创建ApplicationContext实例。首先,让我们先分析ContextLoader接口及其实现。
ContextLoader接口有两个实现:ContextLoaderListener和ContextLoaderServlet。两者都实现同样的功能,但不同的是,ContextLoaderListener不能在与Servlet 2.2兼容的web容器中使用。根据Servlet 2.4规范, servlet context listener要在web应用程序的servlet context建立后立即执行,并要能够响应第一个请求(在servlet context要关闭时也一样):这样一个servlet context listener是初始化Spring ApplicationContext的理想场所。虽然使用哪个完全取决于你,但是在同等条件下应该首选ContextLoaderListener;对于更多兼容性的信息,请查看ContextLoaderServlet的JavaDoc。
你可以象下面那样使用ContextLoaderListener来注册一个ApplicationContext:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- or use the ContextLoaderServlet instead of the above listener
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-->
监听器首先检查contextConfigLocation参数,如果它不存在,它将使用/WEB-INF/applicationContext.xml作为默认值。如果已存在,它将使用分隔符(逗号、冒号或空格)将字符串分解成应用上下文将位置路径。ContextLoaderServlet同ContextLoaderListener一样使用'contextConfigLocation'参数。
- spring学习之ApplicationContext—— ContextLoaderListener和ContextLoaderServlet
- spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn.
- spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn.
- 第九篇 sping深入学习之ContextLoaderListener与ContextLoaderServlet
- spring3.0以后移除ContextLoaderServlet,使用ContextLoaderListener获取ApplicationContext
- spring中ContextLoaderListener和DispatcherServlet区别 ApplicationContext
- 获得Controller 的Map ContextLoaderListener和ContextLoaderServlet
- Spring学习之IOC容器BeanFactory和ApplicationContext(三)
- ContextLoaderListener和Spring MVC中的DispatcherServlet学习
- 共同学习Spring源码--ContextLoaderListener和ContextCleanupListener
- ContextLoaderListener和Spring MVC中的DispatcherServlet学习
- ContextLoaderListener和Spring MVC中的DispatcherServlet学习
- ContextLoaderListener和Spring MVC中的DispatcherServlet学习
- spring——BeanFactory和applicationContext
- Spring-学习笔记(ContextLoaderListener)
- spring mvc 之ContextLoaderListener
- Spring之ContextLoaderListener
- 《Pro Spring》学习笔记之ApplicationContext国际化
- 《COM本质论》第四章学习(1)
- hibernate3.2特性
- apache2.2下ssl配置
- webwork.properties详解
- rpm
- spring学习之ApplicationContext—— ContextLoaderListener和ContextLoaderServlet
- 风云点评:Flash 与 Silverlight 终极大比拼
- 作者讲述《一个操作系统的实现》的故事
- boost简单分析
- 字符指针 不等于 字符数组
- 急事?慢慢地说;小事,幽默地说。说话艺术:
- oracle的EXP和IMP命令
- 090518
- SQL 删除或修改