码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-03-18 12:23:22      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:contextloaderlistene   classnotfoundexcepti   contextconfiglocatio   classloader   

今天在进行了项目的整合的时候使用的是maven工具,当我的项目整合成功以后启动web容器发现了报了下面的异常:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.util.WebAppRootListener


在我的项目当中我也确实配置了下面的信息:

<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.WebAppRootListener
		</listener-class>
	</listener>

开始以为是我的classpath的路径配置出了问题,但是发现我的配置也没有问题,和我项目中的目录相符合:

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:applicationContext.xml
		</param-value>
	</context-param>

找不到“ org.springframework.web.context.ContextLoaderListener”这个类,ContextLoaderListener这个类是在spring-web.jar包下,我仔细检查了项目jar环境,发现该jar包确实存在,而且也能找到编译后的ContextLoaderListener.class文件。

开始还不知为什么,到后来在网上找了写资料终于找到了解决的方法和缘由:

Java虚拟机是根据Java ClassLoader(类加载器)决定如何加载Class。
系统默认提供了3个ClassLoader  
Root ClassLoader,ClassPath Loader,Ext ClassLoader
我们也可以编写自己的ClassLoader,去加载特定环境下的Jar文件。  
能不能加载Jar,加载哪里的Jar,是由ClassLoader决定的。  

楼主的问题可能是 导入的仅仅是jar包的引用,例如在eclipse中通过build path加进user lib……(类似快捷方式)
这种在Java Application中没问题,但在web Application中可能会出现找不到类的异常。
在WEB Application中jar包最好放在webroot或webcontent下的lib文件夹内,特别是xml中用到的jar包。

因为我是通过eclipse的build path直接引用的jar包,没有把jar文件拷贝到lib目录下。

随后我将所需的jar包全部拷贝到WEB-INF/lib下,再重新启动tomcat便能顺利通过了。


注意:不能再build path了,因为maven会自动的引入jar,假如再添加进去了就会有jar的冲突问题。



  1. spring-web 的jar包没导进去

  2. jar包邮冲突,把重复的jar包删除

  3. 在web.xml加上<context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-*.xml</param-value>
            </context-param>

因为默认的读取的是/WEB-INF下的配置文件,如果配置文件在src中要把路径改为类路径底下

4.把工程刷新一下,因为工程是部署在服务器底下的,要把加入的jar包部署到工程里。






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

标签:contextloaderlistene   classnotfoundexcepti   contextconfiglocatio   classloader   

原文地址:http://blog.csdn.net/u011218159/article/details/44408375

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!