gpt4 book ai didi

Grails - 多个数据源

转载 作者:行者123 更新时间:2023-12-02 06:37:45 25 4
gpt4 key购买 nike

首先,让我开始,我已经查看了很多有关在 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'
}

我在这里做错了什么? (如前所述,如果我消除两个辅助数据源(dataSource_mysql 和 dataSource_oracle),一切都会正常工作)。

提前致谢。开发:Ubuntu - Grails 2.3.7 - MySQL - Oracle 11g。

最佳答案

好吧,我明白了。

在 Grails 2.3.7 发行说明中,它说要升级您的休眠版本。我没能做到这一点。

http://grails.org/2.3.7+Release+Notes

运行时':hibernate:3.6.10.10'

然后,在我这样做之后,我不再收到该错误并收到另一个错误

java.lang.ClassNotFoundException:null
在 java.net.URLClassLoader$1.run(URLClassLoader.java:366)
在 java.net.URLClassLoader$1.run(URLClassLoader.java:355)
在 java.net.URLClassLoader.findClass(URLClassLoader.java:354)
在 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
在....MigrationUtils.createInstance(MigrationUtils.groovy:220)
在....MigrationUtils.getDatabase(MigrationUtils.groovy:57)
在....MigrationUtils.getDatabase(MigrationUtils.groovy:116)
在 DbmGenerateGormChangelog$_...doCall(DbmGenerateGormChangelog:52)
在....MigrationUtils.executeInSession(MigrationUtils.groovy:132)
在 DbmGenerateGormChangelog$_run_closure2.doCall(DbmGenerateGormChangelog:51)
在 DbmGenerateGormChangelog$_run_closure1.doCall(DbmGenerateGormChangelog:33)

我以前从未需要为 oracle 指定 hibernate 方言,但显然在最新版本的迁移插件(当前为 1.3.8)中,您必须这样做。

dialect = "org.hibernate.dialect.Oracle10gDialect"

我已经指定了 MySQL 的方言,所以我不知道如果删除它是否会产生相同的错误。

关于Grails - 多个数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22737532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com