跳至主要内容

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.

评论

此博客中的热门博文

AngularJS CakePHP Sample codes

Introduction This sample is a Blog application which has the same features with the official CakePHP Blog tutorial, the difference is AngularJS was used as frontend solution, and CakePHP was only use for building backend RESR API. Technologies AngularJS   is a popular JS framework in these days, brought by Google. In this example application, AngularJS and Bootstrap are used to implement the frontend pages. CakePHP   is one of the most popular PHP frameworks in the world. CakePHP is used as the backend REST API producer. MySQL   is used as the database in this sample application. A PHP runtime environment is also required, I was using   WAMP   under Windows system. Post links I assume you have some experience of PHP and CakePHP before, and know well about Apache server. Else you could read the official PHP introduction( php.net ) and browse the official CakePHP Blog tutorial to have basic knowledge about CakePHP. In these posts, I tried to follow the steps describ

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