跳至主要内容

Deploy application into Cloudfoundry

VMware(the SpringSource's mother company) provides a PAAS cloud service(aka CloudFoundry.com), you can easily deploy your application into CloudFoundry.com via Roo CloudFoundry addon or CloudFoundry.com client tools.
And VMware also provides a Eclipse IDE plugin, with which you can deploy the application into CloudFoundry in IDE, just like deploy into your local server instance.

Configuration for CloudFoundry

The following steps are based on the project we have created in before post.
  1. Add cloudfoundry dependency in your pom.xml.
    <dependency>
    <groupId>org.cloudfoundry</groupId>
    <artifactId>cloudfoundry-runtime</artifactId>
    <version>0.8.2</version>
    </dependency>
    
  2. Configure a cloud data source in spring configuration file applicationContext.xml.
    <beans profile="cloud">
    <cloud:data-source id="dataSource"/>
    </beans>
    
CloudFoundry also supports other service, such as MongoDb, etc, please consult the cloudfoundry online document for more details.

Register a CloudFoundry.com account

Go to Cloudfoundry , click the Create Account button and follow the steps to register an account.
Homepage in cloud

Deploy into CloudFoundry via Roo

There is a roo addon in the Roo repository which provides cloudfoundry support.
Execute addon list in the Roo console, you will get the list of current Roo addons.
If you encounter a warning for the license, follow the warning info and type download accept terms of use to accept the terms of use firstly.
Run the following command to search "cloud" keyword in the search results list.
addon search cloud
You can install the addons by id or bundleSymbolicName. Run the following command and install cloudfoundry addon by the specified bundleSymbolicName option.
addon install bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry 
Now you can use cloudfoundry addon freely as the before existing addons in your local system in Roo console.
Firstly login in cloudfoundry.com,
cloud foundry login --email <email> --password <password>
Create a Cloud ready mysql database service.
 cloud foundry create service --serviceType mysql --serviceName <yourMysqlServiceName>
Deploy your app into cloudfoundry.com,
cloud foundry deploy --appName <yourAppName> --path CREATE
If you do not have a domain for your project, you can specify CREATE value to the path to create a new yourAppName.cloudfoundry.com for your application. Else specify the war path to --path option.
Bind the created MySQL service to your application.
cloud foundry bind service --appName <yourAppName> --serviceName <yourMysqlServiceName>
Start your application,
cloud foundry start app --appName <yourAppName>
You can view the current app list,
cloud foundry list apps
If you see STARTED status of your deployed app, it indicates your application is deployed and running successfully.
Open your browser, go to http://<yourAppName>.cloudfoundry.com.
Homepage in cloud

Deploy into CloudFoundry from Eclipse

Firstly make sure you have installed CloudFoundry Eclipse plugin.
If not, you can switch to the Extension tab in the SpringSource Dashboard interface. And find CloudFoundry in the list, click the checkbox before the CloudFoundry item and hint Install button to install it into your IDE.
  1. Create a CloudFoundry server instance.
    In the Server view, right click the whitespace and hint the New item in the context menu, and open the New server wizard.
    Create a cloudfoudry server instance
    Expand VMware node and select CloudFoundry and press Next button.
    Create a cloudfoudry server instance
    Enter your account info of CloudFoundry.com, click Validate Account to check if the email and password is valid.
    Click Finish button, you will see a CloudFoundry instance in the Server view.
  2. Right click the CloudFoundry node in the Server view, select Add and remvoe... in the context menu.
  3. In the popup dialog, select the created project and press Add button.
    Create a cloudfoudry server instance
  4. Fill the application details.
    Fill the application details
  5. Fill the launch deployment info.
    Fill the launch deployment info
  6. In the next step, you can select the service you want to be bound to this application. You can also create a new service by click the New icon here.
    Service selection
  7. Click Finish button to complete the steps.
You will see a new application node under the CloudFoundry server instance.
Service selection
If it is stopped, try to start it by clicking the Start in the context menu. You can also perform a Full publish to deploy a fresh application into CloudFoundry.
Navigate to the application home page.
RUN
CloudFoundry also provides official client command tools for deploy your application into Cloudfoundry.com. Please go to the Cloudfoundry.com to get more info about this topic.
NOTE: CloudFoundry.com provides a VMWare image for developers in development stage, but your CPU must support Intel-VT(Unlucky, due to lack of Intel-VT support, it does not work on my laptop). you can deploy your project into the local VMWare server instead of the remote CloudFoundry.com service.

评论

此博客中的热门博文

Create a restful application with AngularJS and Zend 2 framework

Create a restful application with AngularJS and Zend 2 framework This example application uses AngularJS/Bootstrap as frontend and Zend2 Framework as REST API producer. The backend code This backend code reuses the database scheme and codes of the official Zend Tutorial, and REST API support is also from the Zend community. Getting Started with Zend Framework 2 Getting Started with REST and Zend Framework 2 Zend2 provides a   AbstractRestfulController   for RESR API producing. class AlbumController extends AbstractRestfulController { public function getList() { $results = $this->getAlbumTable()->fetchAll(); $data = array(); foreach ($results as $result) { $data[] = $result; } return new JsonModel(array( 'data' => $data) ); } public function get($id) { $album = $this->getAlbumTable()->getAlbum($id); return new JsonModel(array("data" =>

JPA 2.1: Attribute Converter

JPA 2.1: Attribute Converter If you are using Hibernate, and want a customized type is supported in your Entity class, you could have to write a custom Hibernate Type. JPA 2.1 brings a new feature named attribute converter, which can help you convert your custom class type to JPA supported type. Create an Entity Reuse the   Post   entity class as example. @Entity @Table(name="POSTS") public class Post implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="ID") private Long id; @Column(name="TITLE") private String title; @Column(name="BODY") private String body; @Temporal(javax.persistence.TemporalType.DATE) @Column(name="CREATED") private Date created; @Column(name="TAGS") private List<String> tags=new ArrayList<>(); } Create an attribute convert

Auditing with Hibernate Envers

Auditing with Hibernate Envers The approaches provided in JPA lifecyle hook and Spring Data auditing only track the creation and last modification info of an Entity, but all the modification history are not tracked. Hibernate Envers fills the blank table. Since Hibernate 3.5, Envers is part of Hibernate core project. Configuration Configure Hibernate Envers in your project is very simple, just need to add   hibernate-envers   as project dependency. <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> </dependency> Done. No need extra Event listeners configuration as the early version. Basic Usage Hibernate Envers provides a simple   @Audited   annotation, you can place it on an Entity class or property of an Entity. @Audited private String description; If   @Audited   annotation is placed on a property, this property can be tracked. @Entity @Audited public class Signup implements Serializa