Chapter 4. Application Configuration
Due to the trend of system architectures increasingly moving to cloud infrastructure, modern applications need the ability to incorporate configurations from one or many sources to accommodate the cloud’s ephemeral nature. Ratpack provides a modern, easy-to-use system and semantic API for consuming and working with configuration details. Application and server configuration can be derived from files within the project, inside a library, or from the filesystem, system properties, and environment variables. In every respect, Ratpack empowers developers to follow the principles outlined by the Twelve Factor App. Regardless of your deployment infrastructure, Ratpack’s configuration system is ready and able to support your application’s needs.
The configuration system allows you to take configuration from one or many sources and map it to typed model objects. Those model objects are then able to be used throughout your application. The use of the serverConfig method on the application definition provides the means for specifying the sources to your configuration. Consider a Groovy application that derives its database connection information from configuration. Example 4-1 outlines an application with a DatabaseConfig class that holds the properties necessary for specifying the connection details.
Example 4-1. Application with DatabaseConfig
importstaticratpack.groovy.Groovy.ratpackimportstaticgroovy.json.JsonOutput.toJsonclassDatabaseConfig ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access