【问题标题】:Grails mongo replica set configuration externalizationGrails mongo 副本集配置外部化
【发布时间】:2015-08-12 18:24:20
【问题描述】:

我们有一个由 grails 2.4.3 开发并使用 MongoDB 3 副本集的 Web 应用程序。 Config.groovy 文件中提到的副本配置。如何从外部属性文件(即 mongo.properties)中读取副本配置。 圣杯{ 蒙哥{ 副本集 = [“mongodev1.test.co:27017”、“mongodev2.test.co:27017”、“mongodev3.test.co:27017”] } }

有人可以指导我吗?

【问题讨论】:

标签: mongodb grails


【解决方案1】:

前段时间我写了一篇关于外部配置的博客:http://lalitagarw.blogspot.com/2014/03/grails-configuration-different-external.html

在您的主配置中定义以下代码。完成后,您可以将外部配置文件放在以下位置:${userHome}/.myConfig/${appName}-config.groovy

appName可以通过你的application.properties文件获取。

def customConfigLocations = []

if (new File("${userHome}/.myConfig/global-config.groovy").exists()) customConfigLocations.add("file:${userHome}/.myConfig/global-config.groovy")

if (new File("${userHome}/.myConfig/${appName}-config.groovy").exists()) customConfigLocations.add("file:${userHome}/.myConfig/${appName}-config.groovy")

if (customConfigLocations.empty) {
        println("No external configuration available......")
}else {
        grails.config.locations = customConfigLocations
        println("loading configuration from: :${grails.config.locations}")
}

【讨论】:

  • 我想使用 .properties 文件而不是 .groovy 文件。
猜你喜欢
  • 2016-06-05
  • 1970-01-01
  • 1970-01-01
  • 2014-08-23
  • 1970-01-01
  • 2017-09-01
  • 1970-01-01
  • 2010-11-01
  • 2013-01-06
相关资源
最近更新 更多