问题描述
因此,如果我想使用Grails在支持多个数据源之前使用的会话来执行直接的SQL查询,那么我可以这样做: def conn = new Sql( sessionFactory.currentSession.connection())
现在问题是我有多个数据源并想要获取特定连接。
我该怎么做?
TIA
SessionFactory
称为 sessionFactory_foo
。因此,您可以像其他任何Spring bean一样依赖注入它: def sessionFactory_foo
并使用它: = new Sql(sessionFactory_foo.currentSession.connection())
So if I want to do a direct SQL query using the session that Grails is using prior to supporting multiple datasources I could do:
def conn = new Sql(sessionFactory.currentSession.connection())
Now the question is that I have multiple datasources and want to grab a connection to a specific one.
How do I do that?
TIA
Given a datasource defined in DataSource.groovy as "dataSource_foo", you'll have a SessionFactory
called sessionFactory_foo
. So you can dependency-inject it like any other Spring bean:
def sessionFactory_foo
and use it like this:
def conn = new Sql(sessionFactory_foo.currentSession.connection())
这篇关于在Grails中获取特定数据源的SessionFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!