grails-用于多个客户端的多个数据库,但是一个源

问题描述:

如何将多个数据库用于多个客户端但只有一个来源.有什么办法可以更改DataSources.groovy文件?

how to use multiple database for multiple client but one source. is there any way to change DataSources.groovy file?

是的,这是可能的.只需将dataSource复制到dataSource文件的顶部并重命名即可(例如datasource2).然后在开发,测试和生产中复制dataSource.用相同的名称重命名新的数据源.

Yes, this is possible. Just copy your dataSource at the top of your dataSource file and rename it (eg datasource2). Then copy the dataSource in the development, test and production. Rename the new dataSources with the same name.

现在,您可以使用与dataSource相同的方式来使用dataSource2了.

Now you are ready to use your dataSource2 with the same way as you use dataSource.

class MySercise {
    def dataSource2

    def myMethod() {
        def sql = new Sql(dataSource2)
    }
}

使用gorm时,请在多个数据源此处支持一章.

When using gorm take a look here at Multiple Data Sources Support chapter.