Deploying Spring Boot Application on OpenShift with Dekorate

More advanced deployments to Kubernetes or OpenShift are a bit troublesome for developers. In comparison to Kubernetes OpenShift provides S2I (Source-2-Image) mechanism, which may help reduce a time required for preparation of application deployment descriptors. Although S2I is quite useful for developers, it solves only simple use cases and does not provide unified approach to building deployment configuration from a source code. Dekorate (, the recently created open-source project, tries to solve that problem. This project seems to be very interesting. It appears to be confirmed by RedHat, which has already announced a decision on including Dekorate to Red Hat OpenShift Application Runtimes as a “Tech Preview”. You can read more about it in this article:

How it Works?

Dekorate is a library that defines a set of annotation processors used for generating and decorating Kubernetes/OpenShift manifests. In fact you just need to annotate your application main class properly and Dekorate will take care of everything else. To use this library you only have to include it in your Maven pom.xml as shown below.


The starter contains not only annotations and annotation processors that may be used on your application, but also support for generation during Maven build, which is executed during compile phase. To enable Decorate during build you need to set property to true. You can also enable deployment by setting property dekorate.deploy to true as shown below.

$ mvn clean install -Ddekorate.deploy=true

Dekorate supports OpenShift S2I. It generates ImageStream for builder and target application, and also BuildConfig resource. If you enable deploy mode it also generates deployment config with required resources. Here’s the screen with logs from Maven build executed on my local machine.


In this case Dekorate is generating OpenShift manifest files and saves them inside directory target/classes/META-INF/dekorate/, and then performing deployment on my instance of Minishift available under virtual address
Unfortunately, we have to modify generated BuildConfig for our convenience. So instead of source type Binary we will just declare Git source repository address.

apiVersion: ""
kind: "BuildConfig"
    app: "sample-app"
    version: "1.1.0"
    group: "minkowp"
  name: "sample-app"
      kind: "ImageStreamTag"
      name: "sample-app:1.1.0"
      uri: ''
    type: Git
        kind: "ImageStreamTag"
        name: "s2i-java:2.3"

In order to apply the changes execute the following commands:

$ oc delete bc sample-app
$ oc apply -f build-config-dekorate.yaml


If you have Spring Boot applications it is possible to completely bypass annotations by utilizing already-existing, framework-specific metadata. To customize the generated manifests you can add dekorate properties to your application.yml or descriptors. I have some problems running these mode with Dekorate, so I avoided it. However, I prefer using annotations on the code, so I prepared the following configuration, which has been succesfully generated:

@OpenshiftApplication(replicas = 2, expose = true, envVars = {
        @Env(name="sample-app-config", configmap = "sample-app-config")
@JvmOptions(xms = 128, xmx = 256, heapDumpOnOutOfMemoryError = true)
public class SampleApp {

    public static void main(String[] args) {, args);
    // ... REST OF THE CODE

In the fragment of code visible above we have declared some useful settings for the application. First, it should be run in two pods (replicas=2). It also should be exposed outside a cluster using OpenShift route (expose=true). The application uses Kubernetes ConfigMap as a source of dynamically managed configuration settings. By annotating the main class with @JvmOptions we may customize behaviour of JVM running on the container, for example by setting maximum heap memory consumption. Here’s the definition of ConfigMap created for the test purpose:

apiVersion: v1
kind: ConfigMap
  name: sample-app-config
  namespace: myproject
  showAddress: 'true'
  showContactInfo: 'true'
  showSocial: 'false'

Sample Application

The sample application code snippet is available on GitHub under repository This very basic Spring Boot web application exposes simple REST API with some monitoring endpoints included with Spring Boot Actuator and API documentation generated using Swagger.


Dekorate is able to automatically detect existence of Spring Boot Actuator dependency and basing on it generate OpenShift readiness and liveness healthchecks definitions as shown below. By default it sets timeout on 10 seconds, and period on 30 seconds. We can override a default behaviour using fields liveness and readiness of @OpenshiftApplication.


The controller class provides implementation for some basic CRUD REST operations. It also injects some environment variables taken from ConfigMap sample-app-config. Basing on their values it decides whether to show or not to show additional person parameters like address, contact information or social links. Here’s an implementation of PersonController:

public class PersonsController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PersonsController.class);

    PersonRepository repository;

    @Value(value = "${showAddress:false}")
    boolean showAddress;
    @Value(value = "${showContactInfo:false}")
    boolean showContactInfo;
    @Value(value = "${showSocial:false}")
    boolean showSocial;

    public Person add(@RequestBody Person person) {"Person add: {}", person);
        return repository.add(person);

    public Person findById(@PathVariable("id") Integer id) {"Person find: id={}", id);
        return hidePersonParams(repository.findById(id));

    public List<Person> findAll() {"Person find");
        return repository.findAll().stream().map(this::hidePersonParams).collect(Collectors.toList());

    private Person hidePersonParams(Person person) {
        if (!showAddress)
        if (!showContactInfo)
        if (!showSocial)
        return person;

Here’s an implementation of a model class. I used Lombok library for getters/setters and constructor generation.

public class Person {

    private Integer id;
    private String name;
    private int age;
    private Gender gender;
    private Address address;
    private Contact contact;
    private Social social;


Here’s a definition of ConfigMap sample-app-config on my instance of Minishift.



The current version of Dekorate uses fabric/s2i-java in version 2.3 as a builder image. It creates ImageStream without any tags, so we have the Docker image from manually by executing the following command:

$ oc import-image fabric/s2i-java:2.3

This commands forces to download some additional versions of a builder image including the newest version for JDK 11. The library still uses the older version of s2i-java image although we have declared JDK 11 as a default version in pom.xml. In this example we can see that Dekorate has still some things to improve 🙂


Assuming we have already performed all the required steps described in the previous sections of this article we may start OpenShift build by running the following command:

$ oc start-build sample-app

The build should be finished successfully as shown below.


After successful build the new image is pushed to OpenShift registry. It triggers start of a new deployment of our application. As you see on the picture below our application is started in two instances, and the route is created automatically.


We can also take a look on environment settings. JVM options has been set, and ConfigMap has been assigned to the deployment config.


Finally we may test sample application. The Swagger API documentation is available under address



I think it is a great idea to use Java annotations for customizing application deployment on Kubernetes/OpenShift. Using Dekorate with frameworks based on annotation processing like Spring Boot greatly simplifies the deployment process for developers. Although the library is on early stage of development and still has some things to improve I’m definitely recommend using it. In this article I’m trying to give you some tips for a quick start. Enjoy 🙂

2 thoughts on “Deploying Spring Boot Application on OpenShift with Dekorate

  1. Great article!

    I really love the idea that builder image selection should be aligned with JDK version defined in the build tool.
    In fact, I just created an issue about it:

    I have a tiny correction, if I may.

    The following phrase is not 100% accurate:

    “The starter contains not only annotations and annotation processors that may be used on your application, but also Maven plugin, which is executed during compile phase”

    Dekorate doesn’t use or define any maven plugin as it aspires to be build tool independent.
    So the dekorate starters are there so that user can add a single dependency and transitively get things like:

    – openshift support
    – spring boot suuport
    – options support

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.