在DataSources.groovy中扩展多个grails DataSources? [英] Extending multiple grails DataSources in DataSources.groovy?
问题描述
您在 DataSource.groovy
中定义的每个环境都会在文件根的外部扩展基础 dataSource
定义
Every environment you define in DataSource.groovy
extends the base dataSource
definition at the root of the file, outside of environments.
我有两个特定的配置,我需要将它们应用于许多具有特定于环境的细微变化的不同环境。确实,我需要两个基本定义,或某种扩展现有定义的方法。
I have two specific configurations that I need to apply to a number of different environments which have minor environment-specific changes. Really, I need two "base definitions", or some way to extend existing definitions.
我该怎么做?
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分配一个闭包(注意=),然后可以在环境块中调用它们。
The following will assign dataSource1 and dataSource2 a Closure (note the =) and you could then call them within your environment blocks.
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()
}
}
}
这篇关于在DataSources.groovy中扩展多个grails DataSources?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!