Difficulty: beginner
Estimated Time: 15 minutes

In this scenario you will learn more about developing Spring Boot Microservices using the Red Hat Runtimes platform. You will learn about Externalized Configurations and how we can use Externalized Configurations to change specific values/variables without having to take down the entire application.

In this scenario you learned about Spring Boot and how it can be used to create Microservices and modify them with Externalized Configuration. We will add additional scenarios that explain more how to build Spring Boot applications on OpenShift shortly, so check back to learn.openshift.com

To summarize: We first deployed our application with the default values. Then we were able to modify the values by editing our application.properties file and rolling out a new version of our application. Our changes were reflected in the live application but didn't require us to have any downtime.

Spring Boot is a powerful and easy to use framework for developing everything from monolithic applications to microservices, but Spring Boot becomes every better when we package it in a container and use an orchestrated platform like OpenShift. When using OpenShift we can, in a very consistent and fast way, deploy our Spring application to multiple environments without worry of environment differences. OpenShift also enables things like Deployment Pipelines and Blue/Green deployments but that was not covered in this scenario.

Additional Resources

More background and related information on Red Hat OpenShift Application Runtimes and Eclipse Vert.x can be found here:

  • Red Hat Runtimes - 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.

Externalized Configuration

Step 1 of 3

Step 1

Import the code

Let's refresh the code we'll be using. Run the following command to clone the sample project:

cd /root/projects && rm -rf rhoar-getting-started && git clone https://github.com/openshift-katacoda/rhoar-getting-started && cd rhoar-getting-started/spring/microservices-externalized-config

Review the base structure of the application

1. Understanding the Application

The project is a simple Greeting application, where a user inputs a fruit name and is greeted by our service. Opening up our src/main/java/com/example/service/FruitController.java file we can see the logic used to respond to our user. The interesting part of this logic is right here, where we retrieve the message:

String message = String.format(properties.getMessage(), name);

If we take a closer look at this properties object, we see that it's of type MessageProperties. When we look at that file src/main/java/com/example/service/MessageProperties.java we see an annotation linking to a configuration prefix, @ConfigurationProperties("greeting"), which is pointing to our src/main/resources/application-local.properties file.

Our application-local.properties file contains only one property, greeting.message. This is the message that we return and display to the user. In order to get an understanding of the flow, let's run the application locally. On the terminal build the project:

mvn spring-boot:run

When the application finishes building, click the local web browser or click here. You should see the same message that is in the application-local.properties file.

Be sure to stop the application with ctrl-c.


You have now successfully executed the first step in this scenario. in the next step we're going to be deploying the project and testing it our for ourselves, as well as modifying this greeting through External Configuration.