Learn to store and retrieve application settings in Play Framework's configuration.
Play Framework keeps the configuration file in /conf/application.conf. Settings may be stored in several formats. For example, storing a database name may be written as a key/value pair:
Or as an object parameter:
Or as a nested group:
If you need to store multiple settings under the same heading, nested groups work best. For example, storing the server and the database name for MongoDB might look like this:
Although a multitude of data types may be stored in the configuration, we would recommend keeping to the basics: integers, decimals, strings, and nulls.
For comments, use either // or # at the beginning of the line.
Reading a configuration setting is quite simple. Add an import statement to the object:
Using the Config Factory, retrieve the values like so:
Config Factory’s load method offers a multitude of getters: getString, getBoolean, getInt, and many more.
To view an example of the configuration, please visit LineDrop’s repository.
Artwork by:Denny Müller
Browse related articles