java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.addAnnotatedClass使用Hibernate Annotation和Maven时

时间:2017-11-04 20:58:13

标签: java

我是Maven和网络技术的新手。我收到错误

" java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava / lang / Class;)Lorg / hibernate / cfg / Configuration; "

在使用hibernate进行CRUD操作时。有人可以查看我的pom.xml并建议我缺少什么(服务器是Tomcat):

 SessionFactory sf = new 
 Configuration().configure().addAnnotatedClass(Inbox.class).
                 addAnnotatedClass(UserControl.class).
                 addAnnotatedClass(UserData.class).
                 addAnnotatedClass(UserData.class).buildSessionFactory(); 

    <dependencies>

        <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.3.11.RELEASE</version>
        </dependency>

        <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.11.RELEASE</version>
      </dependency>

        <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.3.11.RELEASE</version>
        </dependency>

         <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.11.Final</version>
        </dependency>

       <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.6.ga</version>
       </dependency>

       <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
        </dependency>

        <dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
         </dependency>
         <dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
         </dependency>

         <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
       </dependency>
        <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.5.6-Final</version>
       </dependency>  

<!-- Apache Commons FileUpload --> 

       <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.1</version>
      </dependency>

<!-- Apache Commons IO --> 

       <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
      </dependency>

    </dependencies>

1 个答案:

答案 0 :(得分:-1)

您对不同的Hibernate版本有依赖关系

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.11.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.6.ga</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.5.6-Final</version>
</dependency>

如果您使用应用程序服务器,例如Wildfly,则需要禁用与Wildfly捆绑的Hibernate模块。