首先,让我开始,我已经看了很多关于在Grails上配置多个数据源的“正确”方法的网站,其中每一个(Grails 2.0及更高版本)都指向 docs ,但是之后按照文档的说法我得到了这个错误:
Error 2014-03-29 15:48:29,219 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManager_lookup': Cannot resolve reference to bean 'sessionFactory_lookup' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_lookup': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean '$primaryTransactionManager' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '$primaryTransactionManager': 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': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
Message: Error creating bean with name 'transactionManager_lookup': Cannot resolve reference to bean 'sessionFactory_lookup' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_lookup': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean '$primaryTransactionManager' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '$primaryTransactionManager': 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': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
我觉得最有趣的是,如果我指定:
dataSource_lookup
我会得到:
Error initializing the application: Error creating bean with name 'transactionManager_lookup'
如果我将其更改为:
dataSource_mysqldb
我明白了:
Error initializing the application: Error creating bean with name 'transactionManager_mysqldb'
如果我没有指定第二个数据源,那么一切正常。
我的代码:
dataSource {
logSql = true
pooled = true
dialect = org.hibernate.dialect.MySQLInnoDBDialect
driverClassName = 'com.mysql.jdbc.Driver'
username = 'myuser'
password = 'mypass'
url = 'jdbc:mysql://localhost/mydatabase'
dbCreate = 'update'
}
dataSource_mysql {
dialect = org.hibernate.dialect.MySQLInnoDBDialect
driverClassName = 'com.mysql.jdbc.Driver'
username = 'myuser'
password = 'mypass'
url = 'jdbc:mysql://localhost/mydatabase'
dbCreate = 'update'
}
dataSource_oracle {
dialect = org.hibernate.dialect.Oracle10gDialect
driverClassName = 'oracle.jdbc.driver.OracleDriver'
username = 'myuser'
password = 'mypass'
url = 'jdbc:oracle:thin:@localhost:1521:mydatabase'
dbCreate = 'update'
}
我在这里做错了什么? (如前所述,如果我删除了两个辅助dataSources(dataSource_mysql和dataSource_oracle),一切正常)。
提前致谢。 Dev:Ubuntu - Grails 2.3.7 - MySQL - Oracle 11g。
答案 0 :(得分:4)
好的,我想出来了。
在Grails 2.3.7发行说明中,它说升级你的hibernate版本。我做不到。
http://grails.org/2.3.7+Release+Notes
runtime ':hibernate:3.6.10.10'
然后,在我这样做之后,我停止了这个错误并得到了另一个错误
java.lang.ClassNotFoundException: null
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at ....MigrationUtils.createInstance(MigrationUtils.groovy:220)
at ....MigrationUtils.getDatabase(MigrationUtils.groovy:57)
at ....MigrationUtils.getDatabase(MigrationUtils.groovy:116)
at DbmGenerateGormChangelog$_...doCall(DbmGenerateGormChangelog:52)
at ....MigrationUtils.executeInSession(MigrationUtils.groovy:132)
at DbmGenerateGormChangelog$_run_closure2.doCall(DbmGenerateGormChangelog:51)
at DbmGenerateGormChangelog$_run_closure1.doCall(DbmGenerateGormChangelog:33)
我以前从未必须为oracle指定hibernate方言,但显然在最新版本的迁移插件(当前为1.3.8)中,你必须这样做。
dialect = "org.hibernate.dialect.Oracle10gDialect"
我已经指定了MySQL的方言,所以我不知道如果删除它会产生相同的错误。