Grails外部配置文件路径

编程入门 行业动态 更新时间:2024-10-28 10:31:17
本文介绍了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外部配置文件路径

本文发布于:2023-10-07 10:54:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:配置文件   路径   Grails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!