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?
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)
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
.
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.