我正在使用 play-2.3。我想通过 application.conf
加载我的自定义配置文件。但无法加载它。
conf /
application.conf
mycustom.prop
我将 mycustom.prop 包含在 application.conf 中,如下所示。
include file("CAB.prop")
or
include "mycustom.prop"
or
include "mycustom"
以上均无效。
mycustum.prop:
myappIp=x.x.x.x
myappport=1234
在代码中,当我尝试访问 myAppIp 时,它给出了 NullPointerException
MyGlobal.java
import com.typesafe.config.ConfigFactory
...
String ip = ConfigFactory.load().getString("myAppIp"); // this line throws NullPointerException
我不确定,问题出在加载 mycustom.prop
或获取其值时。
最佳答案
编辑:
结果他们只支持一些文件扩展名:https://github.com/typesafehub/config#rationale-for-supported-file-formats 。我测试了各种文件,只有 .properties
、.conf
和 .json
文件被 include
选取。任何其他文件类型都会被默默忽略。
(以下不是问题,尽管 Play 文档声明了这一点,但底层库接受问题中提到的格式 - 保留在这里用于遗留目的)
来自docs :
An include statement consists of the unquoted string include and a single quoted string immediately following it.
应该是这样
include "mycustom.prop"
关于java - 从 application.conf 加载自定义conf文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432059/