gpt4 book ai didi

grails - 在DataSources.groovy中扩展多个grails DataSources?

转载 作者:行者123 更新时间:2023-12-02 13:54:07 25 4
gpt4 key购买 nike

您在DataSource.groovy中定义的每个环境都在环境之外扩展了文件根目录中的基本dataSource定义。

我有两个特定的配置,我需要将它们应用于许多具有特定于环境的细微更改的不同环境。确实,我需要两个“基本定义”或某种扩展现有定义的方法。

我该怎么做?

dataSource1 {
dbCreate = "update"
dialect = org.hibernate.dialect.Oracle10gDialect
pooled = false
jndiName = "java:something"
}
dataSource2 {
pooled = true
driverClassName = "org.hsqldb.jdbcDriver"
username = "sa"
password = ""
dbCreate = "update"
url = "jdbc:hsqldb:mem:testDb"
}

// environment specific settings
environments {
//extend datasource1
production{
}
//extend datasource2
development{
}
}

最佳答案

下面将为dataSource1和dataSource2分配一个Closure(注意=),然后可以在环境块中调用它们。

dataSource1 = {
dbCreate = "update"
driverClassName = "org.hsqldb.jdbcDriver"
dialect = org.hibernate.dialect.Oracle10gDialect
pooled = false
jndiName = "java:something"
}

dataSource2 = {
pooled = true
driverClassName = "org.hsqldb.jdbcDriver"
username = "sa"
password = ""
dbCreate = "update"
url = "jdbc:hsqldb:mem:testDb"
}

environments {
production {
dataSource {
dataSource1.call()
}
}
development {
dataSource {
dataSource2.call()
}
}
}

关于grails - 在DataSources.groovy中扩展多个grails DataSources?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5331868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com