Reputation: 1373
I am new in Akka and want to set up different application.conf
files per environment (test, staging, prod, etc.).
I read the documentation from Akka but I couldn't find a way to do it.
May you know any proper way to have multiple configuration files?
Upvotes: 0
Views: 2578
Reputation: 94
Akka uses the Typesafe Config Library.
The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):
So we usually create an application.conf file in /resources folder.
For different environments, we can create environment specific files like
Using includes, include application.conf at the beginning and specify environment specific configurations which will override the application.conf.
To use a specific environment force a different config source (e.g. from command line -Dconfig.resource=environment.conf)
Start your application using below command:
$ sbt run -Dconfig.resource=development.conf
Upvotes: 3
Reputation: 11479
The options for this aren't so much related to Akka as it is to the config library. Akka uses the default config resolution unless you give it a Config
instance.
With no specific user code to manually select a specific file you have a few options. I think the most useful are the system properties config.resource
to choose a file on the class path (inside the app jar for example), config.file
to use a file from the file system.
Of course you may still have reasons to write your own code to select files as the other answers suggested.
More details in the config library docs: https://github.com/lightbend/config#standard-behavior
Upvotes: 0
Reputation: 8036
A possibility is have a single variable in application.conf which would be "confFile", based on an actual env like
confFile=${?CONF_FILE_NAME}
Then in your code, you load the correspondind file like this
val configFile = ConfigFactory.load().getString("confFile")
val appConf = ConfigFactory.load(configFile)
Upvotes: 0
Reputation: 1578
Here are couple ways to do it.
prod-config : { YOUR_CONFIGURATION_FOR_PROD }
test-config : { YOUR_CONFIGURATION_TEST_ENV }
and so-on
application-prod.conf
to application.conf
Upvotes: 0