I have following conf files in my play2.1.0 application
- application.conf
- override.dev.conf
- override.qa.conf
- override.prod.conf
And there is a application.mode
property in the application.conf file which will have either one of dev/qa/prod values.
application.conf also has a line to include env/mode specific conf files as override. This is what is not working with substitution.
Reason: To have the override properties in the env/mode specific conf files.
Referred: http://www.playframework.com/documentation/2.0/Configuration
If an unquoted
include
at the start of a key is followed by anything other than a single quoted string, it is invalid and an error should be generated.No substitutions are allowed, and the argument may not be an unquoted string or any other kind of value.
Tried:
Able to get the substitution done for another property but not for
include
like thismy.prop="override."${?application.mode}".conf"
The above outputs to
override.dev.conf
ifapplication.mode=dev
If I have something like below its not working and i suppose its what is expected as per the documentation reference.
include "override."${?application.mode}".conf"
Expected the above to include/override props in a file named
override.dev.conf
Question:
- Should this be a future enhancement or this is what is expected out of it?
- What are the other ways to implement what I wanted?
Any help would be really appreciated.
I prefer to override the
GlobalSettings.onLoadConfig
as described in PlayFramework 2 load different config according to current mode. It is done in Scala but it should be possible to do in Java as well.It lets you overload configurations in a very nice way without the need to start the application with command line arguments, you still start the app with
play run
,play start
, etc.You should be able to use this method if you change your
override.qa.conf
tooverride.test.conf
sinceqa
is not a known mode in Play.All shared settings in the
application.conf
and then override in the other ones.We wanted to do something similar and the only way we got it to work was to reverse it.
In each environment we have a
main-config.conf
that has all of the configuration specific for that environment. Basically, what you are calling youroverride.[env].conf
. The first line in each of those files isincludes "application.conf"
to merge in the default configuration for the application. So,application.conf
has the general project configuration and the other files have the stuff specific to the environment.To start your app you just tell it to use the environment-specific config file.
The application will load
main-config.conf
which, in turn, includes the defaultapplication.conf
from the project.We actually also modify the
build
shell script (in the/framework
directory, I believe) so it always specifies that config file parameter. That way we don't have to type that in when we're developing.