Merging multiple TypeSafe Config files and resolving only after they are all merged

前端 未结 1 1061
天涯浪人
天涯浪人 2021-01-30 22:53

I am writing test code to validate a RESTful service. I want to be able to point it at any of our different environments by simply changing an environment variable before execu

相关标签:
1条回答
  • 2021-01-30 23:21

    The answer is to use ConfigFactory.parseResource() in place of ConfigFactory.load().

    Here is the finished result

    private lazy val defaultConfig     = ConfigFactory.parseResources("conf/env/default.conf")
    private lazy val environmentConfig = ConfigFactory.parseResources("conf/env/" + env + ".conf" )
    private lazy val userConfig        = ConfigFactory.parseResources("application.conf")
    private lazy val config = ConfigFactory.load()
                              .withFallback(userConfig)
                              .withFallback(environmentConfig)
                              .withFallback(defaultConfig)
                              .resolve()
    
    0 讨论(0)
提交回复
热议问题