boneash
boneash

Reputation: 158

Referencing to values in typesafe config

I have a config file:

app {
    system {
        action-type = "REST"    
    }
}

roles = [${app.system.action-type} "notifier"]

I want roles to have a value [ RESTnotifier ], but this approach gives me an exception. Any suggestions?

com.typesafe.config.ConfigException$NotResolved: need to Config#resolve() each config before using it, see the API docs for Config#resolve()

Upvotes: 3

Views: 2396

Answers (1)

cmbaxter
cmbaxter

Reputation: 35443

You need to explicitly call resolve on the Config instance if you are going to be using replacements in the config. A quick example showing this:

import com.typesafe.config.ConfigFactory
import collection.JavaConversions._

object ConfigExample extends App{
  val cfgString = """
    app {
        system {
            action-type = "REST"    
        }
    }

    roles = [${app.system.action-type}"notifier"]        
  """

  val cfg = ConfigFactory.parseString(cfgString).resolve()
  println(cfg.getStringList("roles").toList)
}

Note the explicit call to resolve. That should fix your issue.

Upvotes: 7

Related Questions