Skip to content
robpatrick edited this page Apr 19, 2011 · 22 revisions



Grails is a framework for rapidly developing web applications that can be deployed to any Java servlet container, such as Tomcat. Based on the dynamic language Groovy and the Spring framework, it brings the paradigm of Convention over Configuration to the Java platform with the expressiveness of a Java-like dynamic language.

With its focus on making things as easy as possible, Grails is a natural companion for Cloud Foundry and the two finally make the dream of one-step deployment a reality. Simply by installing the Cloud Foundry Grails plugin, you can immediately deploy an application to the Cloud Foundry service via a simple command (assuming you have an account). And if you want your application to use one of the provided services, you just have to install and use the corresponding Grails plugin, for example the Hibernate plugin for the MySQL service, the Redis plugin for Redis, etc. You can install any or even all of these into a single application.

Please see the [installation instructions]( Downloading and Installing) in the official Grails documentation for instructions on how to get going.

If you want to get started right away, try one of our sample applications:

Note that if you wish to deploy these applications yourself, you will need to deploy them under a different application name.

Grails Cloud Foundry Plugin

The Cloud Foundry plugin for Grails adds command line utilities to deploy and manage Grails applications.

To get started you can install the Cloud Foundry plugin for Grails into any Grails application via Grails' install-plugin command:

$ grails install-plugin cloud-foundry

Once this is done type the following command to get more information about the available Cloud Foundry commands:

$ grails cf-help

Assuming you have configured your Cloud Foundry credentials, it is a simple three-step process to create and deploy your first Grails application to Cloud Foundry:

$ grails create-app my-example
$ cd my-example
$ grails install-plugin cloud-foundry
$ grails prod cf-push

For further information on deploying Grails applications to Cloud Foundry refer to the Cloud Foundry plugin documentation.


There are currently 3 services available to Grails applications: SQL, Redis and MongoDB. Each service is enabled automatically if you install the equivalent plugin for either Hibernate (the default GORM implementation), Redis or MongoDB. Note that you do not need to configure any production URL or connection settings, this will happen automatically when your application is deployed. More details of each service are discussed below.


The SQL service is a MySQL database that is automatically provisioned if you have the Hibernate plugin for Grails installed. Grails features an Object-Relational mapper built on Hibernate called GORM which is used to provide transparent persistence to applications. A simple GORM entities looks like the following:

package org.bookstore
class Book {
	String title
	Date releaseDate
	Author author

Grails creates query methods for you, meaning no need to write SQL:

def results = Book.findAllByTitle("The Shining", [max:10, sort:"title", order:"desc", offset:100] )
results = Book.findAllByTitleAndAuthor("The Sum of All Fears", "Tom Clancy")
results = Book.findAllByReleaseDateBetween(firstDate, new Date())
results = Book.findAllByTitleLike("%Hobbit%"

The official GORM documentation ( covers how to go about creating persistent classes and storing instances in a relational database.


Redis will become available to your application if you provision and bind a Redis service to your application or if you simply install the Redis plugin for Grails.

A low-level Redis API is provided allowing you to easily execute Redis commands:
redis["message"] = "World"
println redis["message"]

In addition your can create GORM classes that are mapped to Redis via GORM for Redis. Refer to the plugin documentation for more information.


MongoDB will be available to your application if you provision and bind a Mongo service to your application or if you simply install the MongoDB plugin for Grails.

The MongoDB plugin for Grails allows you to map GORM entities to MongoDB Collections and provides rich querying as was as a low-level API to access the MongoDB driver for Java directly. Refer to the [plugin documentation] ( for more information.

How to

A general tutorial can be found in the blog post "One-step deployment with Grails and Cloud Foundry".


See the Cloud Foundry FAQ for general questions.

Can I use the Spring Cloud Namespace from Grails?

Yes you can! See the documentation on Spring for examples on how to configure additional MySQL, Mongo or Redis instances via the Cloud namespace. This configuration can go into grails-app/conf/spring/resources.xml or grails-app/conf/spring/resources.groovy using the BeanBuilder DSL

How do I get access to Cloud environment variables?

The mechanism is the same for Spring and Grails. See the Cloud Foundry Environment Variables page for more information

Can I send email from my applications?

Currently, no. Only outbound HTTP and HTTPS requests (via proxies) are supported. See the support forum for more info.

You can’t perform that action at this time.