Deploy Spring Boot WAR file on Tomcat in Azure App Service
Hello everyone, Hope you are doing well. In this tutorial, we will learn how to deploy the Spring boot WAR file on tomcat in Azure App Service.
A little bit of Background
Azure App Service
Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile backends. You can develop in your favourite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on both Windows and Linux-based environments. More Info - https://docs.microsoft.com/en-us/azure/app-service/overview
Spring Boot
Spring Boot makes it easy to create stand-alone, production-grade Spring-based Applications that you can "just run". More Info - https://spring.io/projects/spring-boot
Apache Tomcat 9
The Apache Tomcat software is an open-source implementation of the Jakarta Servlet, Jakarta Server Pages, Jakarta Expression Language, Jakarta WebSocket, Jakarta Annotations and Jakarta Authentication specifications. These specifications are part of the Jakarta EE platform.
The Jakarta EE platform is the evolution of the Java EE platform. Tomcat 10 and later implement specifications developed as part of Jakarta EE. Tomcat 9 and earlier implement specifications developed as part of Java EE.
More Info - https://tomcat.apache.org/
GitHub Actions
GitHub Actions helps you automate your software development workflows from within GitHub. You can deploy workflows in the same place where you store code and collaborate on pull requests and issues.
In GitHub Actions, a workflow is an automated process that you set up in your GitHub repository. You can build, test, package, release, or deploy any project on GitHub with a workflow. More Info - https://docs.microsoft.com/en-us/azure/developer/github/github-actions
Steps to Deploy Spring Boot WAR file on Tomcat in Azure App Service
Step 1: Creating a simple spring boot web application.
First, open the Spring initializr https://start.spring.io/
Then, Provide the Group and Artifact name. We have provided Group name com.knf.dev and Artifact springboot-greeting-service. Here I selected the Maven project - language Java - Spring Boot 2.7.1 and add Spring web dependency. The single spring-boot-starter-web dependency transitively pulls in all dependencies cognate to web development.
Then, click on the Generate button. When we click on the Generate button, it starts packing the project in a .zip(springboot-greeting-service.zip) file and downloads the project.
Then, Extract the Zip file.
Step 2: Create a Spring Boot WAR &Import the project on your favourite IDE.
First, we need to package a WAR application instead of a JAR. For this, we'll change pom.xml with the following content:
<packaging>war</packaging>
Next, we'll modify the final WAR file name
<build> <finalName>springboot-greeting-service</finalName> ... </build>
Then we'll add the Tomcat dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
Finally, we'll initialize the Servlet context required by Tomcat by implementing the SpringBootServletInitializer interface:
@SpringBootApplicationpublic class HelloworldApplication extends SpringBootServletInitializer {
public static void main(String[] args) { SpringApplication .run(HelloworldApplication.class, args); }
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application .sources(HelloworldApplication.class); }}
Import the project File -> Import -> Maven ->Existing Maven Project -> Next -> Browse -> Select the project -> Finish
When the project imports prosperously, we can optically discern the project directory in the Package Explorer. The following image shows the project directory:
Add a RestController to be able to test,
@RestControllerpublic class GreetingController {
@GetMapping("greeting") public String greeting() {
return "Hello, world! Greeting from Azure"; }}
Step 3: Create a New Repo and Upload Files on GitHub
First, sign in to Github https://github.com/
Then, create a new repository, for example, "springboot-greeting-service".
Sign in to Azure portal https://portal.azure.com/#home and find "Resource groups" like below.
Then, create a resource group like the one below.
Step 5: Create a Web App and Deploy the code from GitHub Repo
Find "App Services",
Enter/Select necessary information like Resource group, App name, Runtime stack, Java web server stack, OS, Region etc... like above. Then click on the "Deployment" button
Next click on the "Review + create" button and you will be taken to "Review + create", as shown in the image below.
Then, You can see "Deployment is in progress" like the below image.
Once deployment is completed you can see "Your deployment is complete".