This article will show you how to setup your Spring Boot project, so you can deploy it to Openshift.

Installation

First we need to make sure that the application extends from the SpringBootServletInitializer class.
This makes sure Openshift is able to detect and run the application. We also need to override the configure method.

@SpringBootApplication
public class ExampleApplication extends SpringBootServletInitializer {  
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ExampleApplication.class);
    }
    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }
}

The next step is to place the following property in your pom file (openshift doesn't yet support the spring boot default tomcat8) and add the tomcat dependency.

<tomcat.version>7.0.59</tomcat.version>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-tomcat</artifactId>  
<scope>provided</scope>  

The last step is to make sure that maven generates a war instead of a jar file

<packaging>war</packaging>  

Everything is now setup for deploying the spring boot application to openshift!

Author image
Tom Buyse
My name is Tom Buyse. I work for Bewire in Belgium. My primary focus is front-end development, which currently mostly involves Angular, Angular 2 and Ionic.
comments powered by Disqus