Step by step guide about how to deploy your Spring application on CloudBees

3 min read

Spring applications can be easily deployed on CloudBees platform. This is a step by step guide which consolidates our official Spring documentation.

We will assume that you don’t have any Spring application, so we will clone the source code of the Spring PetClinic ClickStart that CloudBees provides. You can use this code as a template for your own Spring projects.

Pre-requisites:

  • You have an account on CloudBees. If not, sign up here . Please, be sure that you have a password on CloudBees platform. If you are signed up through GitHub or Google, we don’t force you to have a password, which is required to use the CloudBees SDK.

  • You have, at least, a free subscription in RUN@Cloud and MySQL. You can add new services on CloudBees once you are signed up here.

  • Install the CloudBees SDK on your computer.

  • If you don’t have your own war file, you will need Maven and Git for the first part of this tutorial.

1. Create your own Spring application

Pre-step: Where am I?

felix@linux-machine:~/CloudBees/github$ pwd
/home/felix/CloudBees/github

Step 1: Clone the PetClinic repository into a new one created on your own computer

felix@linux-machine:~/CloudBees/github$ git clone https://github.com/CloudBees-community/spring-petclinic-clickstart.git
Clonar en «spring-petclinic-clickstart»...
remote: Counting objects: 3634, done.
remote: Compressing objects: 100% (2069/2069), done.
remote: Total 3634 (delta 1209), reused 3412 (delta 1030)
Receiving objects: 100% (3634/3634), 820.47 KiB | 863 KiB/s, done.
Resolving deltas: 100% (1209/1209), done.

Step 2: Create your .war file with Maven

Go to the directory in which you have your repository cloned.

felix@linux-machine:~/CloudBees/github$ cd spring-petclinic-clickstart

Now, you can generate your .war file.

felix@linux-machine:~/CloudBees/github/ spring-petclinic-clickstart $ mvn clean package
…
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.514s
[INFO] Finished at: Fri Oct 18 09:18:21 CEST 2013
[INFO] Final Memory: 21M/169M
[INFO] ------------------------------------------------------------------------

2. Deploying your Spring application on CloudBees

On CloudBees you can create as many environments that you would like. The way in which you can do it is described on our official Spring documentation.

Let’s assume that you would like to create a production environment.

Step 1: Create your application using the CloudBees SDK

In this case, we will deploy the Spring application on a Tomcat 7 container, but you can also deploy it in JBoss, Jetty or Glassfish. The way in which you can use each container is described here.

$bees app:create -t tomcat7 -appName-prod

Step 2: Create your database

$bees db:create dbName-prod

Step 3: Create the database binding

Here we will automatically inject a JNDI datasource into the Tomcat 7 Java container. We use JNDI because it permits you to have multiple environments without modifying your application.

Please, note that if you don’t want to use JNDI for the database binding you will not need to do this step.

$bees app:bind -a appName-prod -db dbName-prod -as mydb

Step 4: Activate Spring Profiles on CloudBees (ONLY IF YOUR APP USES SPRING PROFILES)

PetClinic ClickStart uses Spring Profiles as you can see on the source code here, which will allow you to use different environments at CloudBees platform without doing any modification on your application

$bees config:set -Pspring.profiles.active=javaee

Step 5: Now, you can deploy your application on the platform

$bees app:deploy -t tomcat7 -a appName-prod ~/CloudBees/github/spring-petclinic-clickstart/target/petclinic.war

Felix Belzunce
Support Engineer
CloudBees

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.