【问题标题】:Are configuration settings replaced when adding an external configuration file?添加外部配置文件时是否会替换配置设置?
【发布时间】:2023-04-07 10:38:01
【问题描述】:

在将战争部署到 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()

【问题讨论】:

    标签: tomcat grails configuration configuration-files


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多