Play framework overriding `application.conf` value

2019-03-01 09:09发布

问题:

Play 2.6.x Scala

I have a default application.conf within the folder {project}/conf/ but I'd like to override some values depending on the environment by passing in the respective file as command-line arguments (as detailed in the docs):

sbt run -Dconfig.file=/conf/qa.conf or sbt run -Dconfig.resource=qa.conf

But I'm not able to get play to pick up the overrides. Here's my file directory:

application  
    |- playApp1
    |- playApp2  
       |-- conf  
           |-- application.conf 
           |-- qa.conf

My build.sbt makes playApp2 the default project on load. And I have confirmed that the defulat application.conf is working -- just the override is not.

Thanks for any ideas!

--

Update

Here are the HOCON files play uses. application.conf

platform {
  scheme = "http"
  host = "localhost:8080"
}

and the overrides as provided in qa.conf

include "application.conf"

platform {
  scheme = "https"
  host = "ea311.34.com"
}

回答1:

Your question is about HOCON, in case you did not realize it.

Without seeing your application.conf I can only provide a generic answer. Here is an example of providing a default value for akka.log-config-on-start, which will be overridden by a Java system property or an environment variable called CONFIG_DUMP, if defined:

akka {
  log-config-on-start = false
  log-config-on-start = ${?CONFIG_DUMP}
}

This feature of HOCON is documented here.



回答2:

This works if you provide the command line argument first

sbt -Dconfig.resource=qa.conf run