How to deploy spring boot application with azure app service?

Suthesana
2 min readAug 15, 2020

In the last article we have created the MySQL server and configured it. Let’s see how to configure the azure MySQL server in our spring boot app and deploy it on azure cloud with azure web app service.

First let’s see about What is azure app services?

Azure App Service is a HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your preferred language, be it Java, Ruby, Node.js, PHP, .NET, .NET Core,or Python. Applications run and scale with ease on both Windows and Linux based environments.

some key features of App Service:

Multiple languages and frameworks support

Security and compliance

Managed production environment

Serverless code

Visual Studio and Visual Studio Code integration

Let’s go to the deployment…….

I’m going to deploy my spring boot application as .jar in java runtime.

  1. In our sample project we have to do some configurations in application.properties file.

Replace the values for yourMySQLHost, yourMySQLServerName, yourMySQLServer password with your MySQL server values.And replace the database name also.

2. Next we have to configure our spring boot application to integrate with azure. Copy the below code and change the resource group name and app name with your respective values and add to pom.xml file under plugins configurations.

<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>gs-spring-boot-1559091271202-rg</resourceGroup>
<appName>gs-spring-boot-1559091271202</appName>
<region>westeurope</region>
<pricingTier>f1</pricingTier>
<runtime>
<os>linux</os>
<javaVersion>jre8</javaVersion>
<webContainer>jre8</webContainer>
</runtime>
<!-- Begin of App Settings -->
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<!-- End of App Settings -->
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>

You can change also region and pricingTier according to your preferrence.

3. After configuration we have to build the jar file and deploy it to the Azure. Open terminal and execute mvn clean package to build jar file for deploy.

4.After successful build we are ready to deploy our web app to Azure. Excecute mvn azure-webapp:deploy command in terminal.Maven will deploy your web app to the Azure, if the web app or web app plan does not already exist, it will be created for you.

5.After the successful deployment you can find the deployed web app under the resources in azure portal. Once you click on the deployed web app you can see the details and the url . When you navigate to the url you can see your deployed app is running.

Next topic:.Configuring Azure Redis Cache to boost Spring Boot performance

--

--