问题
Is there a way to use an injected datasource in grails for specific operations such as .createCriteria() , .list(), and .find()?
I have tried the following:
def dataSource_test //Injected dataSource
DomainClass.dataSource_test.createCriteria() //returns no property for domain class
DomainClass.createCriteria(dataSource_test) //returns no matching method for argument
I know it is possible to do the following way:
DomainClass.test.createCriteria()
This way however gives me more issues, linked here: Validation using wrong datasource when using multiple datasources in Grails?
回答1:
Is there a way to use an injected datasource in grails for specific operations such as .createCriteria() , .list(), and .find()?
No. We support multiple datasources and provide a mechanism for expressing which datasource you want a particular query to be associate with, but that isn't what you are asking about. We do not provide a way for you to associate GORM methods with a data source that you have injected into an artifact.
来源:https://stackoverflow.com/questions/26564026/how-to-use-injected-datasource-in-grails-to-perform-operations