如何在Grails中运行时动态设置数据源?

时间:2014-12-28 13:26:25

标签: hibernate grails groovy gorm

如果我有两个数据源:dataSource_1dataSource_2。我如何在运行时根据条件设置数据源 - 例如谁登录?

environments {
    development {
        dataSource_1 {
            dbCreate = "create-drop"
            url = "jdbc:h2:mem:devDb"
        }
        dataSource_2 {
            dialect = org.hibernate.dialect.MySQLInnoDBDialect
            driverClassName = 'com.mysql.jdbc.Driver'
            username = 'lookup'
            password = 'secret'
            url = 'jdbc:mysql://localhost/lookup'
            dbCreate = 'update'
        }
    }
}

0 个答案:

没有答案