添加外部配置文件时配置设置是否被替换?
Are configuration settings replaced when adding an external configuration file?
我对在将 war 部署到 tomcat 时在 grails 2.3.5 中外部化配置设置感到有点困惑。考虑到我在我的应用程序中执行以下操作 config.groovy
// some grails plugin settings
// some grails spring security settings
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.' // just in case
def logDirectory = "${catalinaBase}/logs"
environments {
development {
//some logging settings
grails {
plugin {
aws {
credentials {
accessKey = "local"
secretKey = "local"
}
s3 {
bucket = "local"
}
}
}
}
}
production {
def tomcatConfDir = new File("${System.properties['catalina.home']}/conf")
grails.config.locations << "file:${tomcatConfDir.canonicalPath}/${appName}-config.groovy"
}
}
并且如果我在服务器 运行 tomcat 上创建以下文件:/tomcat/conf/myapp-config.groovy
我的应用-config.groovy
def env = System.getenv()
log4j = { root->
// some log settings
}
grails {
plugin {
aws {
credentials {
accessKey = "production"
secretKey = "production"
}
s3 {
bucket = "production"
}
}
}
}
问题
在 /tomcat/conf/myapp-config.groovy
中是否需要再次输入 some grails plugin settings
和 some grails spring security plugins
等?我的问题是,当我添加外部文件时,我的应用程序 config.groovy 中的值也会被采用吗?另外,我们可以在外部文件中使用 groovy 代码吗?注意我用过 def env = System.getenv()
为了回答您的问题,已合并。你不需要重复自己。 Grails 本质上是加载您的 Config.groovy
,然后将其中的任何值替换为在外部配置文件中找到的值。它还将仅存在于外部配置中的任何值添加到 "merged" 配置中。
与 Config.groovy
一样 groovy 外部配置文件中也允许代码。
我对在将 war 部署到 tomcat 时在 grails 2.3.5 中外部化配置设置感到有点困惑。考虑到我在我的应用程序中执行以下操作 config.groovy
// some grails plugin settings
// some grails spring security settings
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.' // just in case
def logDirectory = "${catalinaBase}/logs"
environments {
development {
//some logging settings
grails {
plugin {
aws {
credentials {
accessKey = "local"
secretKey = "local"
}
s3 {
bucket = "local"
}
}
}
}
}
production {
def tomcatConfDir = new File("${System.properties['catalina.home']}/conf")
grails.config.locations << "file:${tomcatConfDir.canonicalPath}/${appName}-config.groovy"
}
}
并且如果我在服务器 运行 tomcat 上创建以下文件:/tomcat/conf/myapp-config.groovy
我的应用-config.groovy
def env = System.getenv()
log4j = { root->
// some log settings
}
grails {
plugin {
aws {
credentials {
accessKey = "production"
secretKey = "production"
}
s3 {
bucket = "production"
}
}
}
}
问题
在 /tomcat/conf/myapp-config.groovy
中是否需要再次输入 some grails plugin settings
和 some grails spring security plugins
等?我的问题是,当我添加外部文件时,我的应用程序 config.groovy 中的值也会被采用吗?另外,我们可以在外部文件中使用 groovy 代码吗?注意我用过 def env = System.getenv()
为了回答您的问题,已合并。你不需要重复自己。 Grails 本质上是加载您的 Config.groovy
,然后将其中的任何值替换为在外部配置文件中找到的值。它还将仅存在于外部配置中的任何值添加到 "merged" 配置中。
与 Config.groovy
一样 groovy 外部配置文件中也允许代码。