Eclipse报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener解决方案

在使用Eclipse做SSH整合时Tomcat报错

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4149)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
但是Eclipse显示已经导包成功,spring中的类也可以正常使用,

于是找到了http://bbs.csdn.net/topics/3000668792009年的神贴,按照42楼的说法是

If you're using Eclipse and Maven, then the problem is with one particular project settings option:
project properties -> Java EE Module Dependencies -> Maven Dependencies
the last option must be checked (which isn't by default).

上面说到了如果使用Eclipse就必须将项目以来的jar包添加到 Java EE Module Dependencies中,但是在新版的Eclipse中没有这个选项,因此又有Eclipse : Java EE Module Dependencies Is Replaced By Web Deployment Assembly的说明,新版的Eclipse已经使用更加灵活的Deployment Assembly替换掉了Java EE Module Dependencies,因此只要在这里添加上WEB工程中的jar包即可。效果如下图所示:

Eclipse报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener解决方案_第1张图片


PS:关于Java EE Module Dependencies的解释:This property page lets you add a Web Library dependency to utility projects, JAR files or classpath entries. Archive dependencies will be resolved into the WEB-INF/lib folder of the web module at deployment time. Class folder dependencies will be resolved into the WEB-INF/classes folder.



你可能感兴趣的:(Eclipse报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener解决方案)