跳至主要内容

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.
发表评论

此博客中的热门博文

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 thePostentity 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 converter In this example…

Spring Data Mongo: bridge MongoDB and Spring

Spring Data Mongo: bridge MongoDB and SpringMongoDBis one of the most popular NoSQL products, Spring Data Mongo(Maven archetype id is spring-data-mongodb) tries to provides a simple approach to access MongoDB. Configuration Add the following code fragments in your Spring configuration. <!-- Mongo config --> <mongo:db-factory id="mongoDbFactory" host="localhost" port="27017" dbname="conference-db" /> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory" /> </bean> <mongo:repositories base-package="com.hantsylabs.example.spring.mongo" /> Firstly, declare aDbFactorywhich is responsible for connecting to the MongoDB server. Then, register theMongoTemplateobject which envelop the data operations on MongoDB. Lastly addmongo:repositorieswith an essentialbase-packageattribute, Spring will discovery your d…

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 addhibernate-enversas 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@Auditedannotation, you can place it on an Entity class or property of an Entity. @Audited private String description; If@Auditedannotation is placed on a property, this property can be tracked.