我正在尝试使用Intellij调试Grails项目(来自其他开发人员),并遇到以下错误:

ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener  - Error initializing
the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization
of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'transactionManager': Cannot resolve reference to bean
'sessionFactory' while setting bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError:
org.hibernate.cfg.Configuration.setListener(Ljava/lang/String;Ljava/lang/Object;)V
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManagerPostProcessor': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean
property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError:
org.hibernate.cfg.Configuration.setListener(Ljava/lang/String;Ljava/lang/Object;)V

从研究论坛中,我怀疑加载程序是指Hibernate-3中存在的类,而不是Hibernate-4中存在的类。我正在使用IntelliJ的Hibernate插件,但看不到为什么要加载Hibernate-4。

但是,当我创建一个虚拟Grails应用程序时,不会遇到此错误。

有什么想法吗?

最佳答案

您需要运行grails dependency-report。它将生成如下的依赖性报告。

+--- org.grails.plugins:hibernate:3.6.10.18
|    \--- org.hibernate:hibernate-ehcache:3.6.10.Final
|    \--- org.grails:grails-datastore-core:3.1.3.RELEASE
|         \--- org.javassist:javassist:3.17.1-GA
|         \--- javax.transaction:jta:1.1
|    \--- org.grails:grails-datastore-gorm:3.1.3.RELEASE
|    \--- org.grails:grails-datastore-gorm-hibernate:3.1.3.RELEASE
|         \--- org.grails:grails-datastore-gorm-hibernate-core:3.1.3.RELEASE
|              \--- org.grails:grails-datastore-gorm-plugin-support:3.1.3.RELEASE
|              \--- org.springframework:spring-orm:4.0.7.RELEASE
|    \--- org.grails:grails-datastore-simple:3.1.3.RELEASE
|    \--- commons-collections:commons-collections:3.2.1
|    \--- org.hibernate:hibernate-core:3.6.10.Final
|    \--- javax.validation:validation-api:1.0.0.GA
|    \--- org.hibernate:hibernate-validator:4.1.0.Final
|    \--- org.hibernate:hibernate-entitymanager:3.6.10.Final
|    \--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
+--- org.grails.plugins:database-migration:1.4.0
|    \--- org.liquibase:liquibase-core:2.0.5
+--- org.apache.httpcomponents:httpclient:4.2.3
|    \--- org.apache.httpcomponents:httpcore:4.2.2
|    \--- commons-codec:commons-codec:1.6
+--- org.apache.httpcomponents:httpmime:4.2.3

这将列出您项目正在使用的所有功能。搜索hibernate4,看看是否有任何插件引用了hibernate4。删除或升级插件以使用hibernate3。

关于hibernate - 潜在的 hibernate 版本问题:java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.setListener(Ljava/lang/String; Ljava/lang/Object;),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27906702/

10-11 17:02
查看更多