SpringBoot deployment error to OpenShift

When I initially deployed my SpringBoot application to OpenShift, index.html and no other webpages within the app would show up…saw the error below:

503 Service Unavailable

No server is available to handle this request.

I then realized that SpringBoot comes with an embedded Tomcat server for running locally.  I had to figure out a way to “turn off” the embedded Tomcat server so it wouldn’t be a part of the WAR file deployed to OpenShift.

The basic steps are:

Make the embedded servlet container a provided dependency (therefore removing it from the produced war)

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

Add an application initializer like:

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

public class WebInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}

That class is needed in order to be able to bootstrap the Spring application since there is no web.xml used. (Spring Boot is going to use an embedded instance of Tomcat, so we don’t have access to the web.xml file.)

There were also issues with deploying locally once I made these changes(Exception sending context initialized event to listener instance of class org.apache.tomcat.websocket.server.WsContextListener), so I had to remove the following lines from the pom.xml:

 

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.0.1</version>

<scope>provided</scope>

</dependency>

Leave a Reply