我在我的项目中面临一些问题,这是一个Spring MVC项目。在这个项目中,对于持久层,我们使用的是Hibernate。
以下是我的web.xml
详细信息:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/beanRefFactory.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当我尝试运行此项目时,出现以下错误:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是我的classpath jar详细信息:
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/ant-1.6.5.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/ant-antlr-1.6.5.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/antlr-2.7.6.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/aopalliance-1.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/asm-attrs.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/asm.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/aspectjweaver-1.6.9.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/c3p0-0.9.1.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/c3p0-0.9.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/cglib-2.1.3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/cglib-2.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/cglib-nodep-2.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/commons-collections-3.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/commons-collections-3.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/commons-dbcp-1.4.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/commons-pool-1.5.3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/ehcache-1.2.3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/ejb3-persistence.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate-annotations.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate-commons-annotations.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate-entitymanager.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate-search.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate-validator.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/hibernate3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/javassist-3.9.0.GA.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/jta-1.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/jta.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/lucene-core-2.3.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate/oscache-2.4.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/antlr-runtime-3.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/commons-beanutils-1.8.3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/commons-configuration-1.4.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/jstl.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.asm-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.beans-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.context-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.context.support-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.core-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.expression-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.jdbc-3.1.1.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.transaction-3.1.1.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.web-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/org.springframework.web.servlet-3.0.0.M3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/slf4j-api-1.6.6.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/slf4j-log4j12-1.6.6.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/spring-orm-3.2.0.M1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/spring-oxm-3.2.0.M1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring/standard.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/misslenious/mysql-connector-java-5.1.8-bin.jar"/>
任何指针或帮助都非常明显。提前谢谢。
答案 0 :(得分:1)
您的类路径中缺少spring-web jar(spring-web-3.2.0.M2.jar),其中包含此类。
答案 1 :(得分:0)
ContextLoaderListener 用于将Spring与Web应用程序集成。
解决ClassNotFoundException异常执行以下步骤:
如果您正在使用Eclipse和maven,请确保在构建路径中正确包含所有依赖项。 (检查Java Build 路径)
选择&#34;清洁&#34;。
现在尝试运行你的项目。
如果您仍然遇到任何问题并且您正在使用基于maven的项目,请尝试以下步骤:
1.您需要在父项目中声明maven-compiler-plugin
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
确保符合要求的类与目标(1.6)版本兼容。
有些时候包含的项目依赖项是冲突的,因此要解决冲突,请执行这些命令,
mvn依赖:tree -Dverbose -Dincludes = commons-collections
答案 2 :(得分:0)
1.尝试检查jar文件是否包含在lib文件夹中,否则有时jar文件已损坏尝试下载新jar并包含它。 2.它是您为jar文件提供的正确路径吗?可能是你给错了路径。
答案 3 :(得分:0)
尝试使用另一个版本的“spring web.jar”。