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. Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误——SHH框架

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

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

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

  3. 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 ...

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

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

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

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

  6. 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  7. springmvc项目中java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 严重: Error co ...

  8. 错误:找不到类org.springframework.web.context.ContextLoaderListener

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  9. 【转】maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    http://blessht.iteye.com/blog/1104450 http://www.cnblogs.com/zhouyalei/archive/2011/11/30/2268606.ht ...

  10. 使用Maven构建javaWeb项目时,启动tomcat出错:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.conte

    在初学使用maven构建javaWeb的项目的时候,启动tomcat加载时,总是提示如下错误,辛苦一番终于找到解决办法. 严重: Error configuring application liste ...

随机推荐

  1. [Flux] 2. Overview and Dispatchers

    Flux has four major components: Stores, Dispatchers, Views, and Actions. These components interact l ...

  2. Android中悬浮窗口的实现原理和示例代码

    用了我一个周末的时间,个中愤懑就不说了,就这个问题,我翻遍全球网络没有一篇像样的资料,现在将实现原理简单叙述如下: 调用WindowManager,并设置WindowManager.LayoutPar ...

  3. 计算机体系结构-内存调优IPC OOMK

    man ipc [root@server1 proc]# man ipcIPC(2)                     Linux Programmer’s Manual             ...

  4. 再回首,Java温故知新(一):Java概述

    Java发展历程 Java的发展要追溯到1991年,Patrick Naughton(帕特里克·诺顿)和James Gosling(詹姆斯·高斯林)带领Sun公司的工程师打算为有线电视转换盒之类的消费 ...

  5. [iOS开发] 使用第三方字体不生效

    iOS中使用第三方字体并不复杂,通常只需要如下三个步骤: 1. 将第三方字体文件添加到工程(Project)中: 2. 在info.plist中添加一个新的键"Fonts provided ...

  6. Python之路【第十四篇】:AngularJS --暂无内容-待更新

    Python之路[第十四篇]:AngularJS --暂无内容-待更新

  7. SpringSecurity 在MVC 中的简单使用(翻译的,稍加改动)

    Spring Security允许开发人员轻松地将安全功能集成到J2EE Web应用程序中,它通过Servlet过滤器实现“用户自定义”安全检查. 在本教程中,我们将向您展示如何在Spring MVC ...

  8. Node.js + Express + Mongodb 开发搭建个人网站(一)

    一.Node + Express环境搭建 0.去Node官网下载安装node,如果安装了 npm 和 node的话 那么就 安装 全局的 express,-g全局安装 npm install expr ...

  9. Android手机开发者模式设置

    通用设置 情景1 开发者选项已经激活,并且在设置列表中能看到 设置-->开发者选项(开发者选项已经激活) 情景2 开发者选项还没有激活,并且在设置列表中能不能看到 如果没有看到开发者选项是因办手 ...

  10. oracle - 创建数据库

    在服务器端的oracle,用户有点差异,当 我通过 'sqlplus / as sysdba' 命令登陆后,并不能创建数据库,sysdba拥有最高的系统权限,登陆后是 sys,以as sysdba登录 ...