Deploy Spring boot application to App Service Tomcat Stack using generated war file
Published Jan 10 2023 11:19 PM 3,987 Views

Some people usually choose to follow this document to package the Spring Boot application to a jar file and use cli command to deploy the jar file to the app service with Java SE stack. However, you may also choose to package the Spring Boot project to a war file and deploy it to Tomcat. This article shows how you can do it.

Firstly, you need to modify your Spring Boot application entrance class to entend SpringBootServletInitializer class and override configure method:






public class DemoApplication extends SpringBootServletInitializer {  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(DemoApplication.class);  
    public static void main(String[] args) { , args);  






You also need to make sure your project will be package to a war file. In Maven, it is specified in packaging element in the pom.xml:












If you are using Gradle, modify build.gradle as below:






apply plugin: 'war'






You also need to have the following text in Maven to mark the embedded servlet container dependency as provided:






    <!-- … -->
    <!-- … -->






If you are using Gradle:






dependencies {
    // …
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    // …






Then run "mvn clean package" in the project folder or rebuild grade to generate the war file.

You can then create a web app and choose the same Tomcat version as the embedded one of your Spring Boot project. (Currently Tomcat 10 is not supported for Springboot yet).


Once it is created, run below command to deploy the war file to the app service:






az webapp deploy --resource-group <group-name> --name <app-name> --src-path ./<package-name>.war









Version history
Last update:
‎Feb 05 2023 11:15 PM
Updated by: