Grails外部配置文件路径 [英] Grails external config file path

查看:106
本文介绍了Grails外部配置文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要设置一个外部配置文件.所以我正在使用grails插件

I'am about to set up a external config file. So I'm using the grails plugin

compile "org.grails.plugins:external-config:1.1.1"

我创建如下所示的application.groovy

I create the application.groovy that looks like this

grails.config.locations = [
    "/Users/username/application.properties"

]

我的application.config文件正好在这个地方.通过创建一个普通文件,我可以访问它并可以读出它.在我的文件中,我有三个键值对,例如

And my application.config file is exactly in this place. By creating a normal file i have access to it and can read out of it. In my file i have three key value pairs like

firstkey=first
secondkey=second
thirdkey=third

此键仍未添加到我的配置文件中.在放在src目录中的类中,我可以像这样调用配置

Still this keys does not get added to my config file. In the class which is placed in the src directory i am able to call the config like this

Holders.config
//No result on calling one of the keys
Holders.config.thirdkey

让任何人知道我还必须做些什么

Has anyone an idea what I have to do additional

推荐答案

grails.config.locations需要spring

grails.config.locations takes spring resource patterns

尝试

grails.config.locations = [
        "file:///Users/username/application.properties"
    ]

如果文件位于运行该应用程序的用户的主目录中.您甚至可以使用

If the file is in the home directory of the user under which the app is running. You can even use

grails.config.locations = [
            "~/application.properties"
        ]

示例已经在文档此处

您可以为记录器 grails.plugin.externalconfig 启用调试日志级别.如果找不到您配置的任何外部配置文件,它将记录消息.

You can enable debug log level for logger grails.plugin.externalconfig. And it will log messages if any of your configured external config file is not found.

logger("grails.plugin.externalconfig", DEBUG, ["STDOUT"]) 

这篇关于Grails外部配置文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆