Creating and configuring Azure Web App and MySQL to host a Spring Boot application (2/7)
Tags: spring, angular, azure, java
Published: 2019-05-27 14:19:45

---
title: Creating and configuring Azure Web App and MySQL to host a Spring Boot application (2/7)
published: true
description: In this series of blog posts, we are going to deploy a full-stack application to Azure, and learn how to set up many components efficiently, and in a cost-conscious way.
tags: spring, angular, azure, java
series: "Spring and Angular applications on Azure"
---

This blog post is part of a series on "deploying a Spring Boot and Angular application on Azure", here is the full list of posts:

- [Creating a Spring Boot and Angular application for Azure (1/7)](https://dev.to/jdubois/creating-a-spring-boot-and-angular-application-for-azure-1-7-2mb8)
- Creating and configuring Azure Web App and MySQL to host a Spring Boot application (2/7)
- [Using Azure Pipelines to build, test and deploy a Spring Boot and Angular application (3/7)](https://dev.to/jdubois/using-azure-pipelines-to-build-test-and-deploy-a-spring-boot-and-angular-application-3-7-593j)
- [Using Azure Application Insights with Spring Boot (4/7)](https://dev.to/azure/using-azure-application-insights-with-spring-boot-4-7-263i)
- [Using Azure Application Insights with Angular (5/7)](https://dev.to/azure/using-azure-application-insights-with-angular-5-7-4kej)
- [Configuring Azure CDN to boost Angular performance (6/7)](https://dev.to/azure/configuring-azure-cdn-to-boost-angular-performance-6-7-5ebe)
- [Configuring Azure Redis Cache to boost Spring Boot performance (7/7)](https://dev.to/azure/configuring-azure-redis-cache-to-boost-spring-boot-performance-7-7-52dl)

## Creating a resource group

Let's start using Azure! Go to the [Azure portal](https://portal.azure.com/?WT.mc_id=devto-blog-judubois) and create a free account if you don't have one currently. What we will do here shouldn't cost very much, so if you are just testing for one day this should only cost you a couple of Euros and should be covered by your free credits. Please note there are other ways to get free credits, for example if you are student you have the [GitHub student pack](https://education.github.com/pack), or if your enterprise pays you a Visual Studio Enterprise account (which is we what we will use here). 

One great thing with Azure is that you create "resource groups" in which you will add and configure your services. This means that everything we do here will be in a specific resource group, that we will delete at the end of our tests: there is no risk to forget running resources, and pay for them.

Create a "spring-on-azure" resource group:

![](https://thepracticaldev.s3.amazonaws.com/i/9kjv32v9lvk8kjv9xqod.png)

## Creating the Azure MySQL database

In the search box at the top, look for "MySQL" and select "Azure Database for MySQL".

Create a MySQL database using the resource group we configured earlier, and don't forget to modify the default pricing tier! Here we used the least expensive one, which costs about 27 Euros per month (so about 1 Euro if you run it one full day, which should be more than enough for doing this demo).

Please note somewhere your database name, your username and password, as we will need them later in this article.

![](https://thepracticaldev.s3.amazonaws.com/i/xddq8nt4rzvka6xtmrec.png)

Wait for your database to be created (you can skip and read ahead a little bit!), but we are not done yet with the database setup: by default, databases on Azure are protected by a firewall. While security is very important, it's also useful that our database is reachable both by our application and from our development machine, so we need to configure it.

In your MySQL database, go to "Connection security", and select "Allow access to Azure services". You should also click on the "Add client IP" button to automatically add your current IP to the firewall rules.

![](https://thepracticaldev.s3.amazonaws.com/i/owjdl1y7ggoqrvae1keh.png)

Now that your MySQL server is running, you need to create a schema. We are going to use MySQL Workbench in this example, but you can of course use any other database tool.

Connect to your database using the credentials we just set up. Please note that your user name is in the form "username@database", and that you should have configured the MySQL firewall to allow your IP address (see 2 paragraphs above).

![](https://thepracticaldev.s3.amazonaws.com/i/17ih7e8z6ghx9of1futu.png)

Now that you are connected to your database, please create the "bugtracker" schema that we will use. As here we are using JHipster, we only need to create an empty schema (JHipster uses [Liquibase](http://www.liquibase.org/) to update the database schema automatically), but if you are not using JHipster or Liquibase, this is where you could run your SQL update scripts.

## Creating the Azure Web App

There are several ways to host a Spring Boot application on Azure, and the most commons ones are to use virtual machines, use Azure Web Apps, or use Azure Kubernetes Services. Here we're going to use Azure Web Apps, as it provides a fully-managed operating system and JDK (unlike a virtual machine, which you must set up and maintain yourself), and it's also very easy to use and very cost-effective (compared to Azure Kubernetes Service). Please note that Azure Web Apps uses the Zulu OpenJDK, so you have a fully-supported, TCK-compliant JDK, even on older JDK releases.

In the [Azure portal](https://portal.azure.com/?WT.mc_id=devto-blog-judubois), search for "App Services" and create a new application. Please note that:

- We are using Java 11, as Spring Boot applications are just executable Jar files ("make Jar, not War" as my friend [Josh Long](https://twitter.com/starbuxman) says).
- We changed the default machine type to use a "B1", which is very inexpensive yet powerful enough for our needs.

A word on pricing, as here we are trying to budget-conscious: as of this writing, the B1 instances are free the first month, then cost about $30 per month. So that's more than enough for our demo!

![](https://thepracticaldev.s3.amazonaws.com/i/8abgvjt1sy44d3vf29vq.png)

Before creating your Web App, the online wizard will propose a specific tab to add monitoring: of course, you need to select it to create a new "Application Insights" instance for your application. We will configure this in the following parts of this blog series: here also, this is all free for a small to moderate application, and the benefits of monitoring are huge!

![](https://thepracticaldev.s3.amazonaws.com/i/54yc6u1l2ytsaz6n5ndv.png)

Now finish creating your application, and continue reading will your instance is being provisioned!

## Configuring the Azure Web App

Once that your Azure Web App instance is ready, you will need to configure it. Select your Web Application and click on the "Configuration" menu, to modify the application settings. Those will be exposed as environment variables, that Spring Boot will use when booting up.

- You should already have a `APPINSIGHTS_INSTRUMENTATIONKEY` key, which we will use later for configuring Azure Application Insights
- For your database connection, add `SPRING_DATASOURCE_URL`, which should point to the MySQL instance we configured above. With a JHipster application, the value should be like `jdbc:mysql://spring-on-azure-database.mysql.database.azure.com:3306/bugtracker?useUnicode=true&characterEncoding=utf8&
useSSL=true&useLegacyDatetimeCode=false&serverTimezone=UTC`. Of course, you will need to replace `spring-on-azure-database` by your database name.
- Set up a `SPRING_DATASOURCE_USERNAME` variable with your database user name in the form of `username@database`. So if you created a username called `juliendubois` in a database called `spring-on-azure-database`, then you will need to write `juliendubois@spring-on-azure-database` here. 
- Set up a `SPRING_DATASOURCE_PASSWORD` variable with your database password.
- If you want to see your application's debug messages, you can configure the `LOGGING_LEVEL_YOUR_PACKAGE_NAME` key, replacing `YOUR_PACKAGE_NAME` by the package name used in your application. In our sample application, that would be `LOGGING_LEVEL_IO_GITHUB_JDUBOIS_BUGTRACKER` (as the package name is `io.github.jdubois.bugtracker`), and we set it to `DEBUG`.
- If you are using JHipster, we also recommend you create a `JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET` key, and assign it a base64-encoded token that is a least 256 bits long. This will be your production security key, which shouldn't be shared.

![](https://thepracticaldev.s3.amazonaws.com/i/6qfilckir1onn2ndub5y.png)

Your Azure infrastructure should now be ready! In the next post of this blog series, we will use Azure Pipelines to deploy the application automatically.