First, let me start that I have looked so many sites about the "correct" way to configure multiple datasource on Grails, every one of them (with Grails 2.0 and later) pointing to the docs , however after doing what the docs says I get this error:
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?
What I find most interesting is that if I specify:
dataSource_lookup
I will get:
Error initializing the application: Error creating bean with name 'transactionManager_lookup'
And if I change it to:
dataSource_mysqldb
I get:
Error initializing the application: Error creating bean with name 'transactionManager_mysqldb'
If I don't specify a second datasource, everything works just fine.
My code:
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'
}
What am I doing wrong here? (As stated before, if I eliminate the two secondary dataSources (dataSource_mysql and dataSource_oracle) everything works just fine).
Thanks in advance. Dev: Ubuntu - Grails 2.3.7 - MySQL - Oracle 11g.