com.typesafe.config.ConfigException$NotResolved: has not been resolved,

3.3k views Asked by At

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"

2

There are 2 answers

0
Knows Not Much On BEST ANSWER

I solved it myself.

ConfigFactory.parseFile(new File("src/main/resources/application.conf")).resolve()
0
俊杰张 On

I solved it.

Config confSwitchEnv = ConfigFactory.load("env.conf");

the env.conf is in the resources dir.

reference: https://nicedoc.io/lightbend/config