how to use typesafe config library just render file content?

1.5k views Asked by At

I'm use myConfig.root().render(ConfigRenderOptions.concise().setFormatted(true))) print my config content.But I find it contains many other information, such as "version" : "2.4.16", "stdout-loglevel" : "WARNING",etc, which is not defined in my config file.
Where is the info come from?
How can I just print my config file contents?

3

There are 3 answers

1
Jeffrey Chung On BEST ANSWER

You're probably using Akka 2.4.16 (directly or indirectly), in which case the "extra" configuration settings are pulled from the reference.conf, as described in the documentation. The reference.conf contains all the default configuration settings, and your application.conf can override any of those settings.

The ActorSystem merges the reference.conf with your application.conf, as seen here. I don't think there is a way through the Typesafe Config API to render the contents of your application.conf without including the merged settings from reference.conf.

0
LoranceChen On

I use a way to render config with parseResourcesAnySyntax method by separate myConfig with default:

object DataServiceConfig {
  val local = ConfigFactory.parseResourcesAnySyntax("local")
  val online = ConfigFactory.parseResourcesAnySyntax("online")
  val develop = ConfigFactory.parseResourcesAnySyntax("application") //develop environment
  val default = ConfigFactory.load("application") //default environment

  val myConfig = local.withFallback(online).withFallback(develop)
  val combinedConfig = myConfig.withFallback(default)

  def printConf(config: Config): Unit = println(config.root().render(ConfigRenderOptions.concise().setFormatted(true).setJson(true)))


}

print config: DataServiceConfig.printConf(DataServiceConfig.myConfig)

0
lasclocker On

You can use java.util.Properties to just get your file contents, like this:

def getPropByFileName(fileName: String) = {
    val inputStream = this.getClass.getClassLoader.getResourceAsStream(fileName)
    val props = new Properties()
    props.load(inputStream)
    props
}