Search code examples
scalaakkaconfig

Reuse variables in akka config


How can I reuse a config property in a couple of other properties? My simplified real-world example looks like this:

myApp {

  host = "www.myfoohost.com"

  urls {
    url1 = host + "/b" // this...
    url2 = host + "/a" // ... and this do not work
  }
}

Solution

  • That's called substitutions in Typesafe Config, which uses the ${} notation:

    myApp {
      host = "www.myfoohost.com"
    
      urls {
        url1 = ${myApp.host}"/b"
        url2 = ${myApp.host}"/a"
      }
    }