添加外部配置文件时是否更换了配置设置?

时间:2016-04-05 17:27:35

标签: tomcat grails configuration configuration-files

在将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

MyApp的-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 settingssome grails spring security plugins等?我的问题是,当我添加一个外部文件时,我的应用程序config.groovy中的值也会被采用吗?另外,我们可以在外部文件中使用groovy代码吗?请注意我已使用def env = System.getenv()

1 个答案:

答案 0 :(得分:1)

要回答您的问题,请将其合并。你不需要重复自己。 Grails实际上加载了您的Config.groovy,然后使用外部配置文件中找到的值替换其中的任何值。它还会将仅在外部配置中存在的任何值添加到“合并”配置中。

Config.groovy一样,外部配置文件中也允许使用groovy代码。