ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。至于ApplicationContext.xml这个配置文件部署在哪,如何配置多个xml文件,书上都没怎么详细说明。现在的方法就是查看它的API文档。在ContextLoaderListener中关联了ContextLoader这个类,所以整个加载配置过程由ContextLoader来完成。看看它的API说明

第一段说明ContextLoader可以由 ContextLoaderListener和ContextLoaderServlet生成。如果查看ContextLoaderServlet的API,可以看到它也关联了ContextLoader这个类而且它实现了HttpServlet。这个接口

第二段,ContextLoader创建的是 XmlWebApplicationContext这样一个类,它实现的接口是WebApplicationContext->ConfigurableWebApplicationContext->ApplicationContext->BeanFactory这样一来spring中的所有bean都由这个类来创建

第三段,讲如何部署applicationContext的xml文件,如果在web.xml中不写任何参数配置信息,默认的路径是”/WEB-INF/applicationContext.xml,在WEB-INF目录下创建的xml文件的名称必须是applicationContext.xml。如果是要自定义文件名可以在web.xml里加入contextConfigLocation这个context参数:

1. <context-param> 
2. <param-name>contextConfigLocation</param-name> 
3. <param-value> 
4. /WEB-INF/classes/applicationContext-*.xml 
5. </param-value> 
6. </context-param>

在<param-value> </param-value>里指定相应的xml文件名,如果有多个xml文件,可以写在一起并一“,”号分隔。上面的applicationContext-*.xml采用通配符,比如这那个目录下有applicationContext-ibatis-base.xml,applicationContext-action.xml,applicationContext-ibatis-dao.xml等文件,都会一同被载入。

由此可见applicationContext.xml的文件位置就可以有两种默认实现:

第一种:直接将之放到/WEB-INF下,之在web.xml中声明一个listener、

第二种:将之放到classpath下,但是此时要在web.xml中加入<context-param>,用它来指明你的applicationContext.xml的位置以供web容器来加载。按照 Struts2 整合spring的官方给出的档案,写成:

1. <!-- Context Configuration locations for Spring XML files --> 
2. <context-param> 
3. <param-name>contextConfigLocation</param-name> 
4. <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> 
5. </context-param>

org.springframework.web.context.ContextLoaderListener(转载)的更多相关文章

  1. maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    maven 导入项目中经常出现这个问题 严重: Error configuring application listener of class org.springframework.web.cont ...

  2. Eclipse------用Tomcat运行项目后出现:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

    Eclipse中Tomcat运行项目后出现: 严重: Error configuring application listener of class org.springframework.web.c ...

  3. Tomcat启动时报org.springframework.web.context.ContextLoaderListener错误解决方案

    问题现象:新从svn上检出maven的项目maven+spring+springmvc项目在Tomcat启动时,报如下错误. 严重: Error configuring application lis ...

  4. org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderListener

    org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderLi ...

  5. Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误——SHH框架

    SHH框架工程,Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误 1.查看配置文件web.xml中是否配置.or ...

  6. maven 项目启动tomcat报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    maven项目启动tomcat报错: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...

  7. Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  8. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    参考: http://www.cnblogs.com/sunxucool/archive/2013/06/07/3124380.html   ---------------------------&g ...

  9. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.ClassNotFoundException:org.springframework.web.context ...

随机推荐

  1. curl常用选项详解

    curl常用选项详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 又是下班的时间了,让我们一起来学习一下今天的Linux命令吧~我一半只把自己常用的参数列出来,其他的有但是我们几 ...

  2. SpringMvc异常处理

    SpringMvc通过HandlerExceptionResolver处理程序的异常,包括Handler映射.数据绑定.以及方法执行时发生的异常,SpringMvc提供的HandlerExceptio ...

  3. uber 真是垃圾

    uber司机好几次都不认识路,态度也不好,最开始使用是因为它价格最便宜,随着滴滴/快的价格下调,已经没有再使用uber的必要,果断卸载.

  4. GWT入门学习之下载安装

    1.准备 安装 jdk: 下载路径:http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-windows-i586.exe?Aut ...

  5. 机器学习实战-K-nearest neighbors 算法的优缺点

    K临近算法是基于实例的学习,使用算法的时候我们必须要有接近分类结果的实例训练样本数据. 优点:精度高,对异常值不敏感 缺点: 时间复杂度和空间复杂度比较大.(如果训练样本数据集比较大,需要大量的空间来 ...

  6. mysql 配置文件 value

    在xml配置文件中配置数据库utl时,要使用&的转义字符也就是& 例如:<property name="url" value="jdbc:mysql ...

  7. noi 4977 怪盗基德的滑翔翼

    题目链接: http://noi.openjudge.cn/ch0206/4977/ LIS http://paste.ubuntu.com/23406594/

  8. noi 1768 最大子矩阵

    题目链接:http://noi.openjudge.cn/ch0206/1768/ 可能是数据修改了吧,O(n6)过不了了. 主要是在求一个矩阵的和时,重复计算了很多次. 矩阵首先压缩一下.在输入的时 ...

  9. [问题2014A11] 解答

    [问题2014A11]  解答 我们需要利用以下关于幂等阵判定的结论,它是复旦高代书第 142 页的例 3.6.4: 结论  设 \(A\) 为 \(n\) 阶方阵, 则 \(A^2=A\) 当且仅当 ...

  10. JS部分代码分享

    2015-10-12 : 1.search()表达式:搜索索引 <!DOCTYPE html><html><body> <p>搜索字符串 "w ...