Difficulty: beginner
Estimated Time: 5 minutes

Spring Boot on OpenShift

In this example we will learn how to create a simple Spring Boot project using Spring CLI and deploy the same on to Red Hat OpenShift using fabric8 Maven Plugin.

The example application will be a very simple hello world kind of REST API application which will have a REST uri /whereami which will return a text response with the hostname where the application is deployed and running.

Congratulations

You have now learned how to deploy your Spring Boot application on to OpenShift environment.

To Summarize you created a simple Spring Boot project using Spring CLI, added a simple Hello Boot Controller, then deployed it locally to test the API, finally configured the fabric8 maven plugin to the project, which allowed you to deploy the project on OpenShift Container Platform.

Additional Resources

  • Red Hat OpenShift Application Runtimes for Developers - Here you can get started with a project using different boosters and clone that project to your local computer. This also enables you to deploy your application on your own private OpenShift Container Platform or use OpenShift Online that is provided for free from Red Hat.
  • Project Snowdrop homepage - This site has a lot of details of the work that Red Hat is doing to make Spring work great on Kubernetes and OpenShift.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Build and Deploy Spring Boot Application on OpenShift

Step 1 of 4

Step 1

Create Spring Boot project using Spring CLI

1. Create a simple spring boot project via cli

As we will be building a simple REST API with Spring Boot, the project need to have spring-boot-starter-web and spring-boot-starter-actuator as dependencies.

Let us create a project named helloboot with web(spring-boot-starter-web) and actuator(spring-boot-starter-actuator) as project's dependencies.

Click the command below to have project created using Spring CLI:

spring init --artifactId=helloboot --groupId=com.example --dependencies=web,actuator --extract $HOME/helloboot

Click the link below to view the generated pom.xml:

pom.xml

2. Change to project directory

For the convenience of execute maven commands we shall navigate to the project directory:

cd /root/helloboot

Terminal
Local Web Browser
OpenShift Console