今天学习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. ORACLE 日期加减操作

    无论是DATE还是timestamp都可以进行加减操作. 可以对当前日期加年.月.日.时.分.秒,操作不同的时间类型,有三种方法: 1 使用内置函数numtodsinterval增加小时,分钟和秒2 ...

  2. mysql数据表修复

    当数据库表被破坏,运行报错: Table './database/tablename' is marked as crashed and last (automatic?) repair failed ...

  3. Linux 磁盘告警分析

    硬件配置 cat /etc/redhat-release && dmidecode -s system-product-name && cat /proc/cpuinf ...

  4. cannot download, /home/azhukov/go is a GOROOT, not a GOPATH

    问题详情: go环境安装好后,运行go代码也没有问题 下载govendor包的时候提示: cannot download, /home/azhukov/go is a GOROOT, not a GO ...

  5. msysGit在GitHub代码托管

    (转:http://www.cnblogs.com/xing901022/p/4388190.html) 代码的管理,在日常开发中是很重要的环节,程序员的修炼三部曲——版本控制,单元测试,项目自动化. ...

  6. 使用Let's Encrypt加密你的小站

    介绍 Let's Encrypt是一个免费并且开源的CA,且已经获得Mozilla.微软等主要浏览器厂商的根授信.它极大低降低DV证书的入门门槛,进而推进全网的HTTPS化. Certbot is a ...

  7. 从零开始学 Web 之 Vue.js(一)Vue.js概述,基本结构,指令,事件修饰符,样式

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  8. MongoDB 系列文章

    MongoDB 系列文章 本文的内容是基于 MongoDB 4.0 的. 参考于 MongoDB 4.0 官方文档. 搭建 MongoDB从搭建到优化 MongoDB-副本集搭建与管理 管理 Mong ...

  9. Android 监听 ScrollView 滑动到最底部。

    做产品时,有一个需求,需要监听ScrollView滑动到最底部.在网上找了些方法,都有这样或那样的问题,要不就是监听不精确, 要不就是重复监听,那些代码没有产品化,很不可靠. 经过自己试验,终于找到了 ...

  10. 开发php的扩展模块(centos环境下)

    首先下载一份PHP的源码,并上传到centos服务器上 源码下载地址:https://github.com/php/php-src   然后在命令行进入到源码路径下的ext目录 然后创建扩展项目 [r ...