繁体   English   中英

从application.conf加载自定义conf文件时出错

[英]Error in Loading custom conf file from application.conf

我正在使用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 我测试了各种文件,但是include只能拾取.properties.conf.json文件。 任何其他文件类型都将被静默忽略。


(以下不是问题,尽管Play文档指出了这一点,但底层库接受问题中提到的格式-出于传统目的保留在此处)

文档

include语句由未加引号的字符串include和紧随其后的单引号字符串组成。

所以应该

include "mycustom.prop"

您可以尝试在mycustom.prop包括application.conf ,然后使用-Dconfig.resource-Dconfig.file启动激活-Dconfig.file

您的mycustom.prop

include "application.conf"
# much configuration follows

并与启动activator -Dconfig.resource=mycustom.prop如果你的配置文件是在类路径中(例如,在config文件夹中) -或activator -Dconfig.file=/opt/conf/mycustom.prop如果要指定一个路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM