SpringBootServletInitializer tutorial

SpringBootServletInitializer tutorial shows how to deploy a Spring Boot application from a traditional WAR deployment.

The current trend is to deploy Spring Boot application from an executable JAR. (See the Spring Boot first web application for details how to start a simple web application from JAR.)

Spring is a popular Java application framework. Spring Boot is an effort to create stand-alone, production-grade Spring based applications with minimal effort.


SpringBootServletInitializer is an interface to run SpringApplication from a traditional WAR deployment. It binds Servlet, Filter and ServletContextInitializer beans from the application context to the server.

SpringBootServletInitializer example

The application creates a simple Spring Boot RESTful application and packages it into a WAR.

│   ├───java
│   │   └───com
│   │       └───zetcode
│   │           │   Application.java
│   │           └───controller
│   │                   MyController.java
│   └───resources

This is the project structure.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"






This is the Maven build file. The spring-boot-starter-web is starter for building web, including RESTful, applications using Spring MVC.

The application is packaged into a WAR file.

package com.zetcode.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

public class MyController {

    @GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE)
    public String index() {

        return "Hello there";

This is the controller class for the Spring Boot web application. A controller is decorated with the @Restontroller annotation.

@GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE)
public String index() {

    return "Hello there";

A GET request to the home page returns a string. The binding is done with @GetMapping.

package com.zetcode;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

The Application sets up the Spring Boot application. It extends from SpringBootServletInitializer so that it can be deployed as a WAR.

The application can be run both by deploying the WAR on a Tomcat server and executing it as a self-executable web archive with embedded Tomcat.

In this tutorial, we have created our first Spring Boot web application deployable from a traditional WAR. You might also be interested in the related tutorials: Spring Boot first web application, Introduction to Spring web applications, Standalone Spring applications, FreeMarker tutorial, Java tutorial, Introduction to Play, Introduction to Spark, or Introduction to Stripes.