今天学习spring项目的时候出现了下面的错误信息:

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4854)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

虽然问题一眼就知道是这句话:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

但是还是有点迷糊,因为以前练习spring的时候,是把jar包都复制到WEB-INF/Lib目录下的,但是最近练习项目的时候都是自己建立自己不同的User libaraies,很明显我已经导入了这些jar包,但是却提示这样的信息..............

看来自己对于JVM是如何引入我们所需要的第三方jar包的机制,后来去网上仔细搜了以下,才明白其原理,下面不废话,直接重点:

  1. ava虚拟机是根据Java ClassLoader(类加载器)决定如何加载Class。
  2. 系统默认提供了3个ClassLoader
  3. Root ClassLoader,ClassPath Loader,Ext ClassLoader
  4. 我们也可以编写自己的ClassLoader,去加载特定环境下的Jar文件。
  5. 能不能加载Jar,加载哪里的Jar,是由ClassLoader决定的。
  6. 楼主的问题可能是 导入的仅仅是jar包的引用,例如在eclipse中通过build path加进user lib……(类似快捷方式)
  7. 这种在Java Application中没问题,但在web Application中可能会出现找不到类的异常。
  8. 在WEB Application中jar包最好放在webroot或webcontent下的lib文件夹内,特别是xml中用到的jar包。

原来是我们自使用类似于Ant来获取类的时候是不能象UserLibaray来使用的,因为我们建立的是一个web app,而web app使用的是自定义的ClassLoader,而非JVM中的存在的三种ClassLoader(如上面所说),因此它无法识别出我们写在xml文件中的第三方类库的class文件,而只有我们写在src目录下的java文件才能使用,因此,我们必须要把第三方的类库放入到lib目录下,web app 才会识别我们定义在xml中的类了  .

通这个错误,也让我对classloader的认识也进了一步.虽然以前看过周志明的深入JVM一书中关于类加载器分派体系的介绍,但是不太理解,这样一来,自己也多了一些体会.

javalangClassNotFoundException: orgspringframeworkwebcontextContextLoa

 

spring-web 的jar包没导进去
jar包邮冲突,把重复的jar包删除
在web.xml加上<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param>
因为默认的读取的是/WEB-INF下的配置文件,如果配置文件在src中要把路径改为类路径底下
4.把工程刷新一下,因为工程是部署在服务器底下的,要把加入的jar包部署到工程里。

启动报错:javalangClassNotFoundException: orgspringframeworkwebcontextContextLoaderListener

 

jar包不是导入进去就完了,还要buildpath,也就是创建路径。在Myeclipse里面,右键单击你的jar包,点击build path--》add build path。完成创建路径。另外spring的jar包并非只有一个,最基本的有3个。

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL,spring获取context的更多相关文章

  1. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL

    今天学习spring+cxf的时候遇到一个问题:在web.xml中配置了spring的上下文监听器: <listener> <listener-class>org.spring ...

  2. 部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi

    Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL     严重: Error config ...

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

    原文地址:http://www.cnblogs.com/amosli/p/4067665.html 在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.Clas ...

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

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

  5. ssh项目java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误

    错误: 导入别人的ssh项目后出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误, 错 ...

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

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

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

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

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

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

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

随机推荐

  1. 使用 Maven 插件将 class(字节码文件),resource(资源文件),lib(依赖的jar包)分开打包

    1. 在pom文件中对各个插件进行配置 <?xml version="1.0" encoding="UTF-8"?> <project xml ...

  2. 机器视觉编程作业02(00)EM算法

    任务:对图像进行边缘检测 思路: )将图像的灰度数值进行0-255的维度统计: )EM算法分析出几个核心显示区块的灰度: )使用通用的边界检测算法(具体哪一种待定). 编辑于2017.12.24 15 ...

  3. 测试工具之RobotFramework界面基本功能使用

    安装好RobotFramework后,直接在运行或者命令行中执行ride.py即可启动RF 启动完成后的界面如下: 界面很简洁,然后我们开始点击file并创建project: 接下来右键project ...

  4. Spring Session - 使用Redis存储HttpSession例子

    目的 使用Redis存储管理HttpSession: 添加pom.xml 该工程基于Spring Boot,同时我们将使用Spring IO Platform来维护依赖版本号: 引入的依赖有sprin ...

  5. Android开发之漫漫长途 XVII——动画(续)

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  6. JodaTimeUtil日期处理工具类(简单、实用)

    一.maven依赖 <!--joda time--> <dependency> <groupId>joda-time</groupId> <art ...

  7. Spring Cloud Hystrix——熔断器

    1.雪崩效应在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服务消费者 ...

  8. C语言第六讲,数组

    C语言第六讲,数组 一丶什么是数组 数组,就是一整块的连续内存空间. 且类型都是一样的.大小一样 比如: 1.1数组元素的访问 我们要访问数组,例如上面,我们访问元算2,元素3等等怎么访问.. 比如有 ...

  9. Ubuntu中root的默认密码

    原文地址:http://www.cnblogs.com/xuyingying/archive/2008/10/16/1312584.html 安装完Ubuntu后忽然意识到没有设 置root密码,不知 ...

  10. Python pandas学习总结

    本来打算学习pandas模块,并写一个博客记录一下自己的学习,但是不知道怎么了,最近好像有点急功近利,就想把别人的东西复制过来,当心沉下来,自己自觉地将原本写满的pandas学习笔记删除了,这次打算写 ...