Application Configuration

Learn to store and retrieve application settings in Play Framework's configuration.

Share:

Storing Application Settings

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 Application Settings

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.

Example

To view an example of the configuration, please visit LineDrop’s repository.

LineDrop Play/Scala Web Application - Configuration

Reference

Play Framework - Configuration


Artwork by:

unsplash-logoDenny Müller

Related Articles

Browse related articles

Get our stories delivered

From us to your inbox weekly.

Thank you!

Look for our next article in your mailbox.