Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate:Class not found错误(java.lang.NoClassDefFoundError),尽管在Maven中添加了依赖项_Java_Spring_Eclipse_Hibernate_Maven - Fatal编程技术网

Hibernate:Class not found错误(java.lang.NoClassDefFoundError),尽管在Maven中添加了依赖项

Hibernate:Class not found错误(java.lang.NoClassDefFoundError),尽管在Maven中添加了依赖项,java,spring,eclipse,hibernate,maven,Java,Spring,Eclipse,Hibernate,Maven,我正在尝试使用Maven制作一个简单的web应用程序。在运行时,servlet抛出一个异常,称为java.lang.NoClassDefFoundError:org/hibernate/cfg/Configuration 根据堆栈跟踪,在创建会话工厂的第18行抛出错误- 该错误表示它找不到Hibernate配置文件,尽管依赖项是在Maven下添加的。xml文件如下所示-注意依赖关系hibernate core v5.2.10.Final <project xmlns="http:

我正在尝试使用Maven制作一个简单的web应用程序。在运行时,servlet抛出一个异常,称为java.lang.NoClassDefFoundError:org/hibernate/cfg/Configuration

根据堆栈跟踪,在创建会话工厂的第18行抛出错误-

该错误表示它找不到Hibernate配置文件,尽管依赖项是在Maven下添加的。xml文件如下所示-注意依赖关系hibernate core v5.2.10.Final

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.webapp</groupId>
  <artifactId>userinfo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>userinfo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.2.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.4.1.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-annotations -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.3.11.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.3.11.Final</version>
    </dependency> -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-tools 
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-tools</artifactId>
        <version>5.2.0.Final</version>
    </dependency> -->

  </dependencies>
</project>
我交叉检查过,jar也被添加到Maven依赖项选项卡中,并包含/cfg/configuration.class

我不明白可能是什么问题。请建议我如何消除这个错误

有些事情我已经尝试过了,但都没有成功:

更改了要编译的依赖项的名称。 更新并清理了Maven项目 清理并重新启动Tomcat服务器 论坛上的一个答案表明,使用的Hibernate版本之间可能存在冲突。这就是为什么对hibernate工具依赖项进行注释。
任何帮助都将不胜感激。谢谢

您的hibernate工具已被评论

试着加上这个

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-tools</artifactId>
    <version>3.2.0.ga</version>
</dependency>

请尝试以下过程:

清理项目。 更新项目。 从.m2存储库中删除/org/hibernate/目录。 构建项目。 部署构建。
请参考编辑手册。此外,我还尝试将版本更改为3.2.0.ga。没有帮助:org.hibernate.cfg.Configuration类位于hibernate-core-xxx.Final.jar中,它存在于pom.xml中。不要认为将hibernate工具依赖项添加到project会解决这个问题。您是否可以手动将hibernate-core-xxx.Final.jar直接复制到tomcat lib目录,以便tomcat在运行时加载它。这不是永久性的修复,只是为了调试。另外,我想知道您是否在配置类中看到编译错误?谢谢。我尝试了所有这些,但仍然没有帮助问题显然是因为版本冲突。我在同一版本中添加了所有依赖项,这似乎很有帮助。这就是删除冲突版本解决问题的方法。