java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)

java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;),java,spring,hibernate,maven,Java,Spring,Hibernate,Maven,错误 配置 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMeth

错误

配置

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;

4.0.0
com.techy9
techy9CustomerService
战争
0.0.1-Techy9客户服务
techy9CustomerService Maven Webapp
http://maven.apache.org
朱尼特
朱尼特
3.8.1
测试
朱尼特
朱尼特
3.8.1
测试
org.springframework
spring上下文
4.1.6.1发布
org.springframework
春季aop
4.1.6.1发布
org.springframework
SpringWebMVC
4.1.6.1发布
org.springframework
弹簧网
4.1.6.1发布
org.springframework
春季甲虫
4.1.6.1发布
javax.mail
邮件
1.4
org.springframework
弹簧支架
2.0.8
公共文件上传
公共文件上传
1.2.2  
公地io
公地io
1.3.2  
javax.transaction
jta
1.1
org.hibernate
冬眠
3.2.7.ga
org.hibernate
休眠实体管理器
4.3.11.4最终版本
mysql
mysql连接器java
5.1.34  
javax.mail
邮件
1.4.7
techy9CustomerService

pom.xml

    <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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.techy9</groupId>
<artifactId>techy9CustomerService</artifactId>
<packaging>war</packaging>
<version>0.0.1-TECHY9CUSTOMERSERVICE</version>
<name>techy9CustomerService Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- spring-context which provides core functionality -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented 
        programming implementation allowing you to define -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <!-- The spring-webmvc module (also known as the Web-Servlet module) contains 
        Spring’s model-view-controller (MVC) and REST Web Services implementation 
        for web applications -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <!-- The spring-web module provides basic web-oriented integration features 
        such as multipart file upload functionality and the initialization of the 
        IoC container using Servlet listeners and a web-oriented application context -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-support</artifactId>
        <version>2.0.8</version>
    </dependency>


      <!-- Apache Commons Upload -->  
      <dependency>  
       <groupId>commons-fileupload</groupId>  
       <artifactId>commons-fileupload</artifactId>  
       <version>1.2.2</version>  
      </dependency>  

      <!-- Apache Commons Upload -->  
      <dependency>  
       <groupId>commons-io</groupId>  
       <artifactId>commons-io</artifactId>  
       <version>1.3.2</version>  
      </dependency>  

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

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


    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.11.Final</version>
    </dependency>

    <dependency>  
       <groupId>mysql</groupId>  
       <artifactId>mysql-connector-java</artifactId>  
       <version>5.1.34</version>  
    </dependency>  
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>




</dependencies>
<build>
<finalName>techy9CustomerService</finalName>
</build>
</project>

org.hibernate
冬眠
3.2.7.ga
org.springframework
弹簧支架
2.0.8
保持以下内容不变

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

   <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-support</artifactId>
       <version>2.0.8</version>
   </dependency>

org.hibernate
休眠实体管理器
4.3.11.4最终版本

希望这能有所帮助。

在pom中,多个框架的版本相互冲突,并且您也有重复的依赖项

版本混合

  • 弹簧:4.1.6和2.0.8
  • Hibernate 4.3.11.Final和3.2.7.ga
  • **复制** 1.朱尼特 2.javax.mail

    这两个jar都与较新的jar不兼容(反之亦然)

    我强烈建议使用as,它将为您管理依赖项,并帮助您搜索兼容版本

    为此,请在pom中添加以下内容

       <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-entitymanager</artifactId>
           <version>4.3.11.Final</version>
       </dependency>
    
    
    io.spring.platform
    平台物料清单
    1.1.4.1发布
    聚甲醛
    进口
    
    并删除重复和混合版本以及所有版本号。这将给您留下一个类似于下面的pom

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>1.1.4.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    
    4.0.0
    com.techy9
    techy9CustomerService
    战争
    0.0.1-Techy9客户服务
    techy9CustomerService Maven Webapp
    http://maven.apache.org
    io.spring.platform
    平台物料清单
    1.1.4.1发布
    聚甲醛
    进口
    朱尼特
    朱尼特
    测试
    org.springframework
    spring上下文
    org.springframework
    春季aop
    org.springframework
    SpringWebMVC
    org.springframework
    春季甲虫
    javax.mail
    邮件
    文件上传
    文件上传
    公地io
    公地io
    org.hibernate
    休眠实体管理器
    mysql
    mysql连接器java
    techy9CustomerService
    
    这可能是一个依赖性问题。添加pom.xml文件我添加了pom.xml,请帮助我首先不要混合框架的版本,无论是哪个框架。您正在混合来自不同版本(2.0.8和4.1.6)的Spring jar,同时还混合了hibernate版本(4.3.11和3.2.7)。修复那些版本不要建议人们使用旧的
    com.springsource
    bundle。添加
    hibernate entitymanager
    依赖项就足够了。通过执行上述更改获得“缺少工件javax.persistence:com.springsource.javax.persistence:jar:2.0.0”,直到面临相同的问题我删除了spring支持,我使用的是spring上下文支持4.1.6该依赖项已经被引入,
    javax.mail
    依赖项声明两次,删除其中一个(正如我在上面的示例中所做的那样)。
    <?xml version="1.0" encoding="UTF-8"?>
    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.techy9</groupId>
      <artifactId>techy9CustomerService</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-TECHY9CUSTOMERSERVICE</version>
      <name>techy9CustomerService Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>1.1.4.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>
      <dependencies>
        <!-- Test Dependencies -->
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
        </dependency>
        <!-- spring-context which provides core functionality -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
        </dependency>
        <!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented 
        programming implementation allowing you to define -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</artifactId>
        </dependency>
        <!-- The spring-webmvc module (also known as the Web-Servlet module) contains 
        Spring’s model-view-controller (MVC) and REST Web Services implementation 
        for web applications -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-orm</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.mail</groupId>
          <artifactId>mail</artifactId>
        </dependency>
        <!-- Apache Commons Upload -->
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
        </dependency>
        <!-- Apache Commons Upload -->
        <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
        </dependency>
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
        </dependency>
      </dependencies>
    
      <build>
        <finalName>techy9CustomerService</finalName>
      </build>
    </project>