Open In App

Deploying Spring Boot Application with MySQL Database on Azure

Last Updated : 11 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Microsoft Azure is a cloud computing platform through which we can use Microsoft’s resources. It works on different deployment models like Infrastructure as a Service(IaaS), Platform as a Service(PaaS), Software as a Service(SaaS), and Serverless Functions. Cloud Deployment is highly in demand nowadays as users love the concept of the Cloud over on-premise infrastructure.

In this article, we will explain the steps to deploy a Spring Boot application integrated with a MySQL database on the Azure cloud platform. Let us see how to deploy a Spring Boot application with a MySQL database on Azure:

  1. Start by deploying the MySQL database on Azure
  2. Getting ready with MySQL connections
  3. Configuring the Spring Boot application for deployment

Why Choose Azure for Spring Boot Deployment?

Setting up a large physical server will require a lot of money, effort, and physical space. But with Microsoft Azure, you don’t need to worry about this setup. Azure will provide us with virtual machines, fast processing of data, analytical and monitoring tools, and so on to make our work simpler. The pricing of Azure is also simple and cost-effective. Azure uses a “Pay As You Go” model, which means you have to pay only for what you use.

Prerequisites

You must have the following things in your system for the Deployment of the Spring Boot Application with the MySQL Database:

  • Azure account
  • MySQL Workbench installed locally
  • Spring Boot application with Maven
  • GitHub account with your project uploaded

Step-by-Step Guide to Deploying a Spring Boot App to Azure with MySQL Database

The following are the step-by-step instructions that you can follow to deploy a Spring Boot application integrated with a MySQL Database on Azure:

Step 1: Start by deploying the MySQL database on Azure 

  • Open the Azure Portal and Search for MySQL Server to create a resource section.
  • Click creates a resource after providing some basic details like the zone and choosing a plan of your choice.

  • Once the resource creation is done go to your dashboard and open the resource to view its details.
  • Click on Connection security and add the current IP address.
  • Click on Connection String and copy the JDBC connection string and store it for the meantime.
  • Open MySQL Workbench in your local system. 
  • Click on the ‘+’ next to MySQL connections.

Step 2: Getting ready with MySQL connections 

A dialog will open where give a connection name of your choice, provide the hostname as the server name present in the overview section of the Azure MySQL database. Finally, put the username and password which was generated at the time of resource creation.

  • After successfully validating the details click on test connection, and if everything is perfect, then login to the workbench using the above-entered username and password.
  • Create a database of your choice using the command ‘create database “name”‘, the execute ‘use database “name” ‘.

CREATE DATABASE springboot_db;
USE springboot_db;

Step 3: Configuring the Spring Boot Application for Deployment

Open application.properties file and add the following properties in it as provided below:

# Server and Database Config

server.port=8080

spring.datasource.url=jdbc:mysql://your-mysql-server.mysql.database.azure.com:3306/springboot_db?useSSL=true&requireSSL=true

spring.datasource.username=your-admin-user

spring.datasource.password=your-password

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # Updated driver

# Hibernate/JPA Config

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

Step 4: Add MySQL Dependency in pom.xml

pom.xml should use the latest MySQL Connector:

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>8.0.33</version>

</dependency>

Step 5: Run the Spring Boot Application

Now run the application as a Spring-Boot app. Upon running hibernate automatically configures the table structure for your project on the Azure MySQL database.

Step 6: Deploy the App to Azure

  • Create an app service on Azure.
  • Link your GitHub account under the Deployment Center of the App Service. Select the repository and branch that contains your Spring Boot project.
  • Finally hit the create button. 

These steps can be used to deploy a Spring Boot app with MySQL database on the Azure cloud platform.

Note: To see the deployment cycle go to the Actions tab of your Git-hub account and you will find the aforementioned actions in progress. Finally, if the application is error-free then a deployment link will be generated. 


Next Article

Similar Reads