Next we will be creating a controller class. In this class we will be exposing a GET rest endpoint with url /test which returns string "Hello JavaInUse".
package com.javainuse.boot_azure_apps;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/test")
public String test() {
return "Hello JavaInUse";
}
}
Finally we want the deployed spring boot application to run on port 80 so in application.properties specify this.
server.port=80
If we now start the application and go to localhost:80/test we get the output as follows
Azure Webapp Maven Plugin
To the pom.xml we will be adding the azure webapp maven plugin as follows-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.javainuse</groupId>
<artifactId>boot-azure-apps</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-azure-apps</name>
<description>Demo project for Spring Boot</description>
<url />
<licenses>
<license />
</licenses>
<developers>
<developer />
</developers>
<scm>
<connection />
<developerConnection />
<tag />
<url />
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>2.9.0</version>
</plugin>
</plugins>
</build>
</project>
Next we will be building this pom.xml using the maven command -
azure-webapp:config

This will download all the azure-webapp maven plugin dependencies. Also it will create the following configuration for our application.
In the pom.xml abve configuration gets added automatically-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.javainuse</groupId>
<artifactId>boot-azure-apps</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-azure-apps</name>
<description>Demo project for Spring Boot</description>
<url />
<licenses>
<license />
</licenses>
<developers>
<developer />
</developers>
<scm>
<connection />
<developerConnection />
<tag />
<url />
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>2.9.0</version>
<configuration>
<schemaVersion>v2</schemaVersion>
<resourceGroup>boot-azure-apps-1719693557570-rg</resourceGroup>
<appName>boot-azure-apps-1719693557570</appName>
<pricingTier>P1v2</pricingTier>
<region>centralus</region>
<runtime>
<os>Linux</os>
<javaVersion>Java 17</javaVersion>
<webContainer>Java SE</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>
We will be modifying the above generated configuration to specify the resource group name, application name and also sepcify the server port on which the above application
will be running when deployed to azure webapp.
<configuration>
<schemaVersion>v2</schemaVersion>
<resourceGroup>newsub</resourceGroup>
<appName>boot-azure-apps-javainuse</appName>
<pricingTier>P1v2</pricingTier>
<region>centralus</region>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<runtime>
<os>Linux</os>
<javaVersion>Java 17</javaVersion>
<webContainer>Java SE</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
Next in the command prompt login to the azure portal as follows-
az login
Next go to the project location and use the
mvn azure-webapp:deploy command to deploy the jar file to azure app service.

With the above maven command the application gets deployed to azure web apps.
If we now try to access the exposed GET endpoint, we get the output as follows-
Download Source Code
Download it -
Spring Boot 3 + Azure App + JAR Example