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

标签 java playframework playframework-2.3

我正在使用 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/

相关文章:

scala - Play 具有超过22个字段的案例类的json合并格式

scala - 如何使用 Scala/Play 2.3 安排复杂的任务?

java - Vector<Point2D> .add() 替换所有现有元素并追加

java - 将大于 127 的值存储在字节数组中

jax-ws - 从服务器调用 JAX WS Web 服务,无需 http 或 servlet

java - Play Framework 中的发布请求中的表单值为null

tomcat - 在tomcat上部署 Play Framework

amazon-web-services - 在 AWS Beanstalk Docker 上部署 Play 框架时出错

java - 使用 JAXB 将 XML 解析为不同的数据结构

java - 无法使用 JAXB 解析 XML 响应 - IndexOutOfBoundsException