Deploying a Spring Boot Web Application on Azure App Service
Hello everyone, Hope you are doing well. In this tutorial, you will learn to how to deploy the Spring Boot application to Azure App Services using Azure Portal.
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
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 Web Application to 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 helloworld. 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(helloworld.zip) file and downloads the project.
Then, Extract the Zip file.
Step 2: Import the project on your favourite IDE, I am using Eclipse IDE
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,
GreetingController.java
@RestControllerpublic class GreetingController {
@GetMapping("greeting") public String greeting() {
return "Hello, world! Greeting from Azure"; }}
Then, test the application locally
Step 1: mvn clean install
Step 2: Run the Spring Boot application - mvn spring-boot:run
The application is running fine locally and I can access it using localhost:8080
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 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".