typesafe.config - 外部配置文件不工作

typesafe.config - external config file is not working

我的类路径中有 application.conf 文件,包含在 jar 中:

{    
  db.class : "org.h2.Driver"
  db.url : "jdbc:h2:~/database.db"
  db.username : sa
  db.password : ""
}

我希望我的应用程序使用外部 .conf 文件,即 /home/user/cfg/app.conf:

{    
  db.class : "org.h2.Driver"
  db.url : "jdbc:h2:~/prod.db"
  db.username : someusername
  db.password : somepassword
}

我使用 -Dconfig.file 选项启动我的应用程序:

java -Dconfig.file="/home/user/cfg/app.conf" -jar application.jar

但是 ConfigFactory.load() 仍然从类路径加载 application.conf,忽略外部文件。

我做错了什么?

您是否碰巧在 Standard behavior 阅读了类型安全配置的标准行为?

或许你可以试试他们的建议。

它说 "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" 包含原始默认配置文件;在 include 语句之后,您可以继续覆盖某些设置。"