Spring Boot Deployment through Cloud Foundry Eclipse

Spring Boot and Cloud Foundry

Spring Boot allows for easier development of Spring based stand-alone Java or web applications. Spring Boot is ideal for Platform as a Service (PaaS), and is a great way to develop applications that run on Cloud Foundry.

Pivotal Web Services (PWS) powered by Cloud Foundry offers a wide variety of services readily available to deployed applications, whether Spring Boot, traditional war web applications, or other supported types like Node.js. In addition, it provides automatic runtime setup for applications through buildpacks, like the Java buildpack for applications that run on a JVM.

To deploy a Spring Boot application in Eclipse, users need only drag and drop their application project to a PWS target created by Cloud Foundry Eclipse, a joint tooling collaboration between Pivotal Software, Inc. and IBM. The Cloud Foundry runtime setup, application deployment and startup, and creation of services used by the application like an SQL database, are all taken care of for the user by the tooling and Cloud Foundry. Application scaling is also easily performed, and project changes can be incrementally pushed through the Cloud Foundry Eclipse UI . This allows for smooth deployment and management of an application from the same Eclipse environment where the application is developed.

In this article, we cover how straightforward and simple it is to create a Spring Boot application in Spring Tool Suite (STS), an Eclipse based development environment for Spring applications, and deploy it to a PWS target using Cloud Foundry Eclipse.

Creating a Spring Boot Application

STS provides a wizard to easily create a Spring Boot project that is ready to run locally or deployed to Cloud Foundry. This is done simply by opening the Eclipse New Project wizard and selecting "Spring Starter Project".



The wizard provides a large number of ways to configure a Spring Boot application. In addition, a user can select the type of packaging that is need for the application, whether jar if it is meant to be a stand-alone Java application, or war if it is to be deployed to a container like Tomcat. Either packaging is supported in Cloud Foundry.

STS also features a Getting Started guide through the same New Project wizard. Selecting "Import Spring Getting Started Content" in the wizard creates a Spring project that is deployable to Cloud Foundry following these guide instructions.

Once the project is created and it appears in the Eclipse workspace, deploying it to Cloud Foundry requires three simple steps:

  1. Configuring the application for Cloud Foundry deployment. This is only required if the application was packaged as jar. It’s not needed for war applications. In the Package Explorer, right click on the Spring Boot project and select:
    Configure -> Enable as Cloud Foundry App
  2. Creating a Cloud target.
  3. Drag and dropping the Spring Boot project to the Cloud target.

Cloud Foundry Eclipse comes pre-installed in STS 3.6.3 and higher. It can also be installed into Eclipse Java EE that uses a Java 7 JRE through the Eclipse Marketplace.

Deploying to Cloud Foundry

To deploy to PWS, account registration is required.

Cloud Foundry Eclipse integrates into Eclipse Web Tools Platform, and creating a Cloud target where an application can be deployed to is a simple task of creating a new server instance through the WTP New Server wizard.

Open the New Server wizard and select "Cloud Foundry" under "Pivotal".


Once created, the Cloud Foundry server instance appears in the Eclipse Servers view and it maps to the Cloud space where the application will be deployed.

Now the application project simply needs to be drag and dropped to the Cloud target in the Eclipse Servers view.


During the deployment process, an application deployment wizard will prompt the user to enter the deployment details for the application. The wizard is pre-populated with default values, so a user can just click "Finish" to deploy immediately or "Next" to further configure the deployment.


Deployment properties that a user can modify include the application URL, memory, and environment variables, like for example defining JAVA_OPTS.

Navigating through the same wizard will also open the Services selection page, where a user can create and bind service instances to the application.

The list of services varies based on the Cloud target, and is populated with up-to-date content from the user’s space.



Among the types of services that a user can create in PWS are SQL databases and messaging services like RabbitMQ. Once created, some of these services need to be bound to an application in order to be used. This binding is also done in the same Services selection page.

Once a user clicks "Finish", the deployment process completes, and an Eclipse console is automatically opened showing the progress of the deployment, including staging of the application by the buildpack.


Managing the Application

When the application is successfully deployed, it will appear in the Servers view under the Cloud target, and the deployed application will be linked to the workspace project. Changes to the workspace project can be published via WTP “Publish” in the Servers view, or through the Cloud Foundry editor, which is opened by double clicking on the application.

The editor contains two tabs:

1. "Overview", which shows information regarding the Cloud target, like the space name and user credentials.


2. "Applications and Services", where a user can scale the application, manage services, view a running application’s stats like CPU and memory usage, and incrementally push changes in the application project via "Update and Restart".


Enhancing the Development Experience

This article showed how a Spring Boot application can easily be created and deployed to Cloud Foundry in an Eclipse development environment. Further enhancements to the development experience include debugging support, which is currently featured in Cloud Foundry Eclipse 1.8.1 for certain applications through a "Debug" button in the editor, and JRebel integration available in version 1.8.2. A comprehensive view of Cloud Foundry Eclipse can also be found here.

About the Authors

nireaj

Nieraj Singh
Pivotal Software, Inc.