有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring MVC 4.2.2和Hibernate 5.0.2给出错误

以下是pom的依赖版本详细信息。xml

<!-- spring --> 
<org.springframework-version>4.2.2.RELEASE</org.springframework-version>
<org.springframework.data-version>1.11.0.RELEASE</org.springframework.data-version>

<!-- hibernate --> 
<org.hibernate.hibernate-core>5.0.2.Final</org.hibernate.hibernate-core> 
<org.hibernate.hibernate-annotations>3.5.6-Final</org.hibernate.hibernate-annotations> 
<org.hibernate.hibernate-commons-annotations>3.2.0.Final</org.hibernate.hibernate-commons-annotations> 
<org.hibernate.hibernate-validator>5.2.2.Final</org.hibernate.hibernate-validator>

我从“spring orm”pom中选择了Hibernate版本的细节,发现Hibernate 5.0.2与spring 4.2.2兼容

Spring coreHibernate的情况下,具有相同的依赖性,它工作正常,并给出了预期的结果。 但是通过集成Spring MVC和Hibernate,它给出了以下错误

Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V

如果需要更多信息,请在评论部分填写。我将提供完整的配置细节

提前感谢。:-)

Dependency Hierarchy


共 (1) 个答案

  1. # 1 楼答案

    从pom中删除以下依赖项。xml解决了这个问题

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

    由于这种依赖关系,在已解决的依赖关系上存在冲突。(参考问题所附图片)

    hibernate注解不是必需的,它依赖于较旧版本的hibernate核心hibernate commons注解

    hibernate commons注解(5.0.2版)作为依赖jar出现在hibernate core中。所以在pom中不需要提及旧版本。xml