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.
Installing the Cloud Foundry plug-in is easy. Open the STS Dashboard and select the Extensions tab in the lower-left corner of the dashboard view. Scroll down to the Server and Clouds section and choose the Cloud Foundry integration plug-in from there. Click and follow the on-screen instructions.
Deploying the application is also very simple.
Open the Servers view, right-click somewhere in it, and create a → .
In the New Server window, choose → and click .
Fill in the account information that you received by email from cloudfoundry.com and choose VMware Cloud Foundry - http://api.cloudfoundry.com from the URL dropdown.
You can click 'Validate Account' to make sure that you filled in your password correctly.
Click 'Finish' to finish the installation of the Cloud Foundry server.
Once the new server is installed, you can add your project to it, just like you would add your project to any other server using the Servers view. Once added, right-click on the project and choose . This will ask for a name that identifies your project in the cloud as well as the URL to deploy to. After giving this information, the project will be uploaded and started in the cloud. After a few seconds, you should be able to visit the URL you provided and see your project in action.
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.
Bind a MySQL database to the application in Eclipse. In the Cloud Foundry view:
Double-click the application deployed in Cloud Foundry
Select Services and click in the upper-right corner
Give the connection a name and choose a MySQL database
Drag the created service from the Services panel to the Services table in the application
Remove the dependency to the HSQLDB that we used at first from pom.xml
Add the MySQL connector dependency as follows:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.15</version> </dependency>
Add the Cloud Foundry runtime dependency as follows:
<dependency> <groupId>org.cloudfoundry</groupId> <artifactId>cloudfoundry-runtime</artifactId> <version>0.6.1</version> </dependency>
Edit the persistence.xml file and change the org.eclipse.persistence.platform.database.HSQLPlatform class name to org.eclipse.persistence.platform.database.MySQLPlatform.
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">
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" />