[英]Error in Loading custom conf file from application.conf
I'm using play-2.3. 我正在使用play-2.3。 I want to load my custom config file through
application.conf
. 我想通过
application.conf
加载我的自定义配置文件。 But could not load it. 但是无法加载。
conf /
application.conf
mycustom.prop
I'm including mycustom.prop in application.conf as follow. 我将mycustom.prop包含在application.conf中,如下所示。
include file("CAB.prop")
or
include "mycustom.prop"
or
include "mycustom"
None of above worked. 以上都不起作用。
mycustum.prop: mycustum.prop:
myappIp=x.x.x.x
myappport=1234
In code when I'm trying to accessing myAppIp, it gives me NullPointerException
在代码中,当我尝试访问myAppIp时,它给了我
NullPointerException
MyGlobal.java MyGlobal.java
import com.typesafe.config.ConfigFactory
...
String ip = ConfigFactory.load().getString("myAppIp"); // this line throws NullPointerException
I'm not sure, either problem is in loading mycustom.prop
or while geting its values. 我不确定,这是加载
mycustom.prop
或获取其值时出现的问题。
Edit: 编辑:
Turns out they only support a few file extensions: https://github.com/typesafehub/config#rationale-for-supported-file-formats . 原来,它们仅支持一些文件扩展名: https : //github.com/typesafehub/config#rationale-for-supported-file-formats 。 I tested various files, and only
.properties
, .conf
and .json
files are picked up by include
. 我测试了各种文件,但是
include
只能拾取.properties
, .conf
和.json
文件。 Any other file types are silently ignored. 任何其他文件类型都将被静默忽略。
(the following is not the problem, although the Play docs state this, the underlying library accepts the format mentioned in the question - kept here for legacy purposes) (以下不是问题,尽管Play文档指出了这一点,但底层库接受问题中提到的格式-出于传统目的保留在此处)
An include statement consists of the unquoted string include and a single quoted string immediately following it.
include语句由未加引号的字符串include和紧随其后的单引号字符串组成。
So it should be 所以应该
include "mycustom.prop"
You could try including the application.conf
in the mycustom.prop
and then start activator with with -Dconfig.resource
or -Dconfig.file
. 您可以尝试在
mycustom.prop
包括application.conf
,然后使用-Dconfig.resource
或-Dconfig.file
启动激活-Dconfig.file
。
Your mycustom.prop
: 您的
mycustom.prop
:
include "application.conf"
# much configuration follows
And start with activator -Dconfig.resource=mycustom.prop
if your config file is on the classpath (eg in the config folder) - or with activator -Dconfig.file=/opt/conf/mycustom.prop
if you want to specify a path. 并与启动
activator -Dconfig.resource=mycustom.prop
如果你的配置文件是在类路径中(例如,在config文件夹中) -或activator -Dconfig.file=/opt/conf/mycustom.prop
如果要指定一个路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.