gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:40:41 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com