【问题标题】:Grails configuration ConfigSlurperGrails 配置 ConfigSlurper
【发布时间】:2014-08-26 21:54:07
【问题描述】:

我想将配置文件分成几个小部分。在Config.groovy 中,我定义了grails.config.locations 数组来指向这些文件:

grails.config.locations = [
    "classpath:config.properties",
    "classpath:some-config.groovy",
]

然后我通过访问来检查配置映射:grailsApplication.config

第一个配置文件是Java属性文件,加载正常:

config.properties

grails.serverURL=http://localhost:8080/selly
..

第二个是.groovy文件,参考文档(http://grails.org/doc/latest/guide/conf.html#configExternalized)应该从自动解析的ConfigSlurper文件格式加载:

some-config.groovy:

app {
    testvar {
        foo = true
    }
}

但是grailsApplication.config.app 不存在(调试中没有字段并且println 返回空映射[:])。

谁能举个加载 groovy 文件的例子?

文件放置在:grails-app\conf\,例如grails-app\conf\config.properties

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

    看起来您已经正确配置了这两个文件。 grailsApplication.config.app 可能只是因为它不是叶节点而为空,你试过grailsApplication.config.app.testvar.foo 吗?

    【讨论】:

    • 你好@Dónal。是的,我试过grailsApplication.config.app.testvar.foo,但它也是空地图[:]。尾随逗号无关紧要 (groovy.codehaus.org/JN1015-Collections)。
    • @Athlan 感谢链接,我不知道尾随逗号是正式允许的。我不确定为什么这不起作用,您能否通过将.groovy 配置文件转换为.properties 文件来解决此问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2013-01-23
    • 2017-09-24
    • 2010-12-18
    • 2018-02-16
    • 1970-01-01
    相关资源
    最近更新 更多