Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Variable Substitutions Between Multiple Config #790

Open
RechaviaAmit opened this issue Jul 7, 2023 · 1 comment
Open

Resolving Variable Substitutions Between Multiple Config #790

RechaviaAmit opened this issue Jul 7, 2023 · 1 comment

Comments

@RechaviaAmit
Copy link

I'm encountering an issue while attempting to load two configs in Scala using the Typesafe Config library, where the second config needs to reference variables in the first one. I probably doing something wrong but I can't find any online solution.

Here is my code:

class ScalaCentralSharedLibConfigManager() {
  val configString =
    """
      |logger {
      |  elasticsearch {
      |    servers {
      |      prod {
      |        host = "http://example.com"
      |      }
      |    }
      |  }
      |}
      """.stripMargin
  var internalConsulConfig: Config = ConfigFactory.parseString(configString).resolve()
  var internalConfig: Config = ConfigFactory.load("sharedlibapplication.conf").withFallback(internalConsulConfig).resolve()

Within my sharedlibapplication.conf I have the following:

elasticSearch {
   prod {
      host = ${logger.elasticsearch.servers.prod.host}
   }
}

When I run the code, I get the error: "Could not resolve substitution to a value: ${logger.elasticsearch.servers.prod.host}"
Any guidance or assistance with this issue would be much appreciated.

The desired output is:

println(internalConfig.getString("logger.elasticsearch.servers.prod.host"))
-- >> "http://example.com"
@havocp
Copy link
Collaborator

havocp commented Jul 7, 2023

the docs for load(String) explain the likely issue - load does the resolve already before you add the fallback. You could use parse instead, or could use load(Config).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants