Reputation: 31546
I am trying to read the following config file using typesafe config
common = {
jdbcDriver = "com.mysql.jdbc.Driver"
slickDriver = "slick.driver.MySQLDriver"
port = 3306
db = "foo"
user = "bar"
password = "baz"
}
source = ${common} {server = "remoteserver"}
target = ${common} {server = "localserver"}
When I try to read my config using this code
val conf = ConfigFactory.parseFile(new File("src/main/resources/application.conf"))
val username = conf.getString("source.user")
I get an error
com.typesafe.config.ConfigException$NotResolved: source.user has not been resolved, you need to call Config#resolve(), see API docs for Config#resolve()
I don't get any error if I put everything inside "source" or "target" tags. I get errors only when I try to use "common"
Upvotes: 7
Views: 3684
Reputation: 11
I solved it.
Config confSwitchEnv = ConfigFactory.load("env.conf");
the env.conf
is in the resources
dir.
reference: https://nicedoc.io/lightbend/config
Upvotes: 0
Reputation: 31546
I solved it myself.
ConfigFactory.parseFile(new File("src/main/resources/application.conf")).resolve()
Upvotes: 15