Next start the spring boot application

If we now go to localhost:8080/employees to get the list of employees that we had previously inserted in mysql database.
We will now be changing the MySQL configuration in the properties file to make use of the azure mysql instead of the local instance.
spring.datasource.url= jdbc:mysql://javainuse-mysql.mysql.database.azure.com/javainusedb?createDatabaseIfNotExist=true
spring.datasource.username= javainuse
spring.datasource.password= Hello@123
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto= update
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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.javainuse</groupId>
<artifactId>boot-mysql-crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-mysql-crud</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.javainuse</groupId>
<artifactId>boot-mysql-crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-mysql-crud</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</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-mysql-crud-rg1</resourceGroup>
<appName>boot-mysql-crud1</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>boot-mysql-crud-rg1</resourceGroup>
<appName>boot-mysql-crud1</appName>
<pricingTier>P1v2</pricingTier>
<region>centralus</region>
<runtime>
<os>Linux</os>
<javaVersion>Java 17</javaVersion>
<webContainer>Java SE</webContainer>
</runtime>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<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 for getting all the employees , we get the output as follows-
Let us insert some records in the azure mysql database as follows-

If we now try to get the employee records we get the output as follows-
Download Source Code
Download it -
Spring Boot + MySQL + Azure App + JAR Example