Difficulty: intermediate
Estimated Time: 15 minutes

Spring Boot Service Discovery and Invocation 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 explore on how to do Service Discovery and invocation of Spring Boot applications deployed on OpenShift. For simplicity of the example we will build a Calculator Application which exposes REST API for its add, subtract, multiply and divide. The calculator service will be consumed by another Spring Boot application called helloboot-discovery to perform a simple add operation called /randomadd which will invoke the Calculator add method with two random numbers.

The main goal of this example is to show how you existing Spring Boot application with Netflix OSS components such as Ribbon could be used as it is within OpenShift, with Spring Cloud Kubernetes modules providing the necessary implementation of Discovery Client for Kubernetes


You have now learned how to deploy a simple Spring Boot Service(Calculator), and build a consumer (helloboot-discovery) that can consume the Calculator Service via Netflix OSS components(Ribbon) from within OpenShift Environment with the help of Spring Cloud Kubernetes modules which provides the necessary implementation of Discovery Client for Kubernetes

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.
  • fabric8 maven plugin - the maven plugin that helps to perform a super easy deployment of Java Applications on to Kubernetes

Spring Boot Service Discovery and Invocation on OpenShift

Step 1 of 10

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 simplecalculator 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=simplecalculator --groupId=com.example --dependencies=web,actuator,lombok --extract $HOME/simplecalculator

2. Change to project directory

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

cd $HOME/simplecalculator

3. Add json dependency to pom.xml

Click the link below to open the pom.xml:


Add the following dependency to the pom.xml dependencies:

<dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> </dependency>

Local Web Browser
OpenShift Console