Cloud Foundry (http://cloudfoundry.com/) is a new platform-as-a-service solution from SpringSource. Cloud Foundry makes it extremely easy to deploy applications created with Spring Roo and Vaadin to the cloud.

Before you can deploy to Cloud Foundry, you must register an account at http://cloudfoundry.com/. The activation might take some time, so you should do the registration several days before you need the account.

The final part of our demonstration is to bind the application deployed in the Cloud Foundry to a real DBMS. In the following, we describe how you can bind the application to a MySQL database.

  1. Bind a MySQL database to the application in Eclipse. In the Cloud Foundry view:

    1. Double-click the application deployed in Cloud Foundry

    2. Select Services and click Add in the upper-right corner

    3. Give the connection a name and choose a MySQL database

    4. Drag the created service from the Services panel to the Services table in the application

  2. Remove the dependency to the HSQLDB that we used at first from pom.xml

  3. Add the MySQL connector dependency as follows:

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.15</version>
    </dependency>
  4. Add the Cloud Foundry runtime dependency as follows:

    <dependency>
      <groupId>org.cloudfoundry</groupId>
      <artifactId>cloudfoundry-runtime</artifactId>
      <version>0.6.1</version>
    </dependency>
  5. Edit the persistence.xml file and change the org.eclipse.persistence.platform.database.HSQLPlatform class name to org.eclipse.persistence.platform.database.MySQLPlatform.

  6. Edit the applicationContext.xml file and change the following line:

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop= ...

    to the following:

    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cloud="http://schema.cloudfoundry.org/spring"
      xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring.xsd">
  7. Also in the applicationContext.xml replace the following:

    <bean class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" id="dataSource">
      <property name="driverClassName"
                value="${database.driverClassName}"/>
      <property name="url" value="${database.url}"/>
      <property name="username" value="${database.username}"/>
      <property name="password" value="${database.password}"/>
    </bean>

    with the following:

    <cloud:data-source id="dataSource" />