[英]typesafe.config - external config file is not working
I have application.conf file on my classpath, included in the jar:我的类路径上有application.conf文件,包含在 jar 中:
{
db.class : "org.h2.Driver"
db.url : "jdbc:h2:~/database.db"
db.username : sa
db.password : ""
}
And I want my app to use external .conf file, which is /home/user/cfg/app.conf:我希望我的应用程序使用外部 .conf 文件,即 /home/user/cfg/app.conf:
{
db.class : "org.h2.Driver"
db.url : "jdbc:h2:~/prod.db"
db.username : someusername
db.password : somepassword
}
I launch my app with -Dconfig.file option:我使用 -Dconfig.file 选项启动我的应用程序:
java -Dconfig.file="/home/user/cfg/app.conf" -jar application.jar
But ConfigFactory.load() still loads application.conf from classpath, ignoring the external file.但是 ConfigFactory.load() 仍然从类路径加载application.conf ,忽略外部文件。
What am I doing wrong?我做错了什么?
Did you happen to read through the Standard behavior of typesafe config at Standard behavior ?您是否碰巧在标准行为中通读了类型安全配置的标准行为?
Perhaps you could try their suggestion.也许你可以试试他们的建议。
It says "These system properties specify a replacement for application.{conf,json,properties}, not an addition. They only affect apps using the default ConfigFactory.load() configuration. In the replacement config file, you can use include "application" to include the original default config file; after the include statement you could go on to override certain settings."它说“这些系统属性指定了 application.{conf,json,properties} 的替代品,而不是附加品。它们只影响使用默认 ConfigFactory.load() 配置的应用程序。在替代配置文件中,您可以使用 include “application “包含原始默认配置文件;在包含语句之后,您可以继续覆盖某些设置。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.