以下是 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 core 和 Hibernate 的情况下具有相同的依赖关系,它工作正常并给出所需的结果。 但是通过 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
如果需要更多信息,请在评论部分留言。我将提供完整的配置详细信息。
提前致谢。 :-)
最佳答案
从 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-annotations不是必需的,它依赖于旧版本的hibernate-core和hibernate-commons-annotations
hibernate-commons-annotations(版本 5.0.2)作为依赖 jar 存在于 hibernate-core 中。因此不需要在 pom.xml 中提及旧版本
关于java - Spring MVC 4.2.2 和 Hibernate 5.0.2 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33667812/