Configuring Service Connections for Grails

Cloud Foundry provides extensive support for connecting a Grails application to
services such as MySQL, Postgres, MongoDB, Redis, and RabbitMQ.
In many cases, a Grails application running on Cloud Foundry can automatically
detect and configure connections to services.
For more advanced cases, you can control service connection parameters yourself.

Auto-Configuration

Grails provides plugins for accessing SQL (using
Hibernate),
MongoDB, and
Redis services.
If you install any of these plugins and configure them in your Config.groovy
or DataSource.groovy file, Cloud Foundry reconfigures the plugin with
connection information when your app starts.

If you use all three types of services, your configuration might look like this:

The url, host, port, databaseName, username, and password fields in this configuration will be overriden by the Cloud Foundry auto-reconfiguration if it detects that the application is running in a Cloud Foundry environment. If you want to test the application locally against your own services, you can put real values in these fields. If the application will only be run against Cloud Foundry services, you can put placeholder values as shown here, but the fields must exist in the configuration.

Manual Configuration

If you do not want to use auto-configuration, you can configure the Cloud
Foundry service connections manually.

Follow the steps below to manually configure a service connection.

Add the spring-cloud library to the dependencies section of your
BuildConfig.groovy file.