我的 hibernate 有问题。问题:创建 ServletContext 资源 [/WEB-INF/spring/appServlet/servlet-context.xml] 中定义的名为“emf”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.NoSuchMethodError: org.hibernate.cfg.Environment.verifyProperties(Ljava/util/Map;)V
它是 xml 文件(servlet 上下文):http://pastebin.com/BRYvbVTg
而且,我只有一个来自 hibernate 的依赖项:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.4.Final</version>
</dependency>
在classpath中,尝试添加所有包,效果相同
完整堆栈跟踪:http://pastebin.com/wJy7QfPW
最佳答案
- 正如 @v.ladynov 提到的,提供完整的堆栈跟踪。
- 要删除本地库,请找到并导航到 .m2 文件夹/repository/org,然后删除 hibernate 文件夹
- 考虑将您的entityManagerFactory定义为
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="ru.mrchebik.model"/>
希望这会有所帮助!
关于java - NoSuchMethodError - org.hibernate.cfg.Environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40664780/