On startup of your application, Play is automatically configured to load application.conf
from the classpath. To override this with an alternative you need to specify this on startup.
Note that whether you are deploying to Windows and starting the app with a .bat
, or Linux with a .sh
you are usually executing that file as follows:-
$ target/universal/stage/bin/<project-name>
The above will execute your .bat
file (if you are on Microsoft that is).
Specifying an alternative config file (couple of options)
So if you want to have separate configuration files for prod/dev then use the default application.conf
for dev and use a production.conf
for prod.
If you put application.conf
inside conf
then you would specify it as follows:-
$ /path/to/bin/<project-name> -Dconfig.resource=production.conf
If application.conf
is not packaged with your app (ie. you have not put it in conf
then you need to specify full path using.
$ target/universal/stage/bin/<project-name> -Dconfig.file=/full/path/to/conf/production.conf
An alternative approach (inheriting and overriding application.conf)
Include application.conf
in prod.conf
and just override what you need to for prod
Note that you can include configuration inside another, so what I usually do is specify a prod.conf
like this:-
include "application.conf"
key.to.override=blah
Then specify prod.conf
when you start the app and application.conf
will automatically be included. You can then just specify the properties in prod.conf
that override those in application.conf
for your production environment.
More
Not that you can also use system properties and environment variables to override settings in application.conf
. I encourage you to take some time to read the docs to understand the options more fully.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…