6

我在我的项目中遇到了一些问题,这是一个 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)

这是我的类路径 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"/>

任何指针或帮助都是非常可观的。提前致谢。

4

4 回答 4

1

您在包含此类的类路径中缺少 spring-web jar (spring-web-3.2.0.M2.jar)。

于 2012-09-13T22:48:12.513 回答
0

1.尝试检查 jar 文件是否包含在 lib 文件夹中,否则有时 jar 文件已损坏尝试下载新的 jar 并包含它。2.您为jar文件提供的路径是否正确?可能是您提供了错误的路径位置。

于 2014-05-16T05:12:55.333 回答
0

ContextLoaderListener用于将 Spring 与 Web 应用程序集成。

要解决 ClassNotFoundException 异常,请执行以下步骤:

  1. 检查 (spring-web.jar) spring-web-3.2.0.RELEASE.jar 的类路径 (如果您使用 spring 3.x 运行,对于 spring spring 2.0 在类路径中添加 spring.jar)
  2. 如果您正在使用 Eclipse 和 maven,请确保所有依赖项都正确包含在构建路径中。(检查 Java 构建路径)

  3. 通过选择“清洁”来清洁您的服务器。

现在尝试运行您的项目。

如果您仍然遇到任何问题并且您正在使用基于 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)版本兼容。

  1. 有时包含的项目依赖项会发生冲突,因此要解决冲突,请执行以下命令,

    mvn 依赖:tree -Dverbose -Dincludes=commons-collections

于 2014-05-05T05:21:20.503 回答
0

尝试使用另一个版本的“spring web.jar”。

于 2014-05-24T14:23:47.273 回答