简体   繁体   English

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

[英]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文档指出了这一点,但底层库接受问题中提到的格式-出于传统目的保留在此处)

From the docs : 文档

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.

相关问题 如何从 play 框架中的 application.conf 文件中读取属性? - How to read a property from the application.conf file in play framework? 检查是否没有application.conf - Check if there is no application.conf 在application.conf中包含的conf文件中使用Play Server的ID - Use ID of Play Server in a conf file included in application.conf 从 application.conf 获取敏感数据 - Fetching sensitive data from application.conf 强制 pureconfig 使用 -dconfig.file application.conf 文件而不是资源 application.conf - force pureconfig to use -dconfig.file application.conf file and not resource application.conf 哎呀。 conf/routes 或 conf/application.conf 丢失。? - Oops. conf/routes or conf/application.conf missing.? 如何在子项目之间共享application.conf文件? - How to share application.conf file between subprojects? 使用激活器启动播放服务器引发application.conf找不到错误 - Starting play server with activator throw an application.conf not found error application.conf 文件中的 AWS Api 凭证 - 足够安全吗? - AWS Api Credentials in application.conf file - Safe enough? 使用 Play 从 java 类访问 application.conf 属性! 2.0 - Accessing the application.conf properties from java class with Play! 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM