scalatypesafe-config

Load multiple config Files


product1.conf

data {

 key1 {
        some-field = "some-value"
        product1 {
                  path = ${some-path}
                 }
      }
     }

product2.conf

data {

 key1 {
        some-field = "some-value"
        product2 {
                  path = ${some-path}
                 }
      }
     }

Desired Conf that needs to be Loaded -

data {

 key1 {
        some-field = "some-value"
        product1 {
                  path = ${some-path}
                 }
        product2 {
                  path = ${some-path}
                 }
      }
     }

In the example shown above, I have multiple conf files and all of them are required to be loaded. Previously I have tried having one single conf file instead of multiple and with the above-desired structure did help me load the configurations using -

val config = ConfigFactory.load(ConfigFactory.parseFile(new File(<path>)).resolve())
args.withFallback(config)

.

I would need help to load multiple config files. Thanks in Advance


Solution

  • Assuming that the conf files are statically knowable, you can have an application.conf like this

    include "product1"
    include "product2"
    

    which will effectively merge the two configurations.