>> Welcome to Azure Tips and Tricks.
In this episode, we are going to run
a Java Spring Boot microservice in Azure Spring Apps.
To follow along, you'll need Visual Studio code
and a Java Development Kit on your machine.
You can find a download link for this in the video description.
Let's get started.
First, we create an Azure Spring Apps instance in Azure.
Here it is. Let's create it.
First I'll pick a resource group.
Now I'll give it a name like this.
I'll leave the rest as it is and then create the instance.
I'll skip to when it is done.
Here is the Azure Spring Apps.
In here, I can create apps
which in this case will be a microservice.
I'll give the app a name like this,
and the rest seems okay.
Create it. What's next?
Let's create MySQL Server.
The microservice will use this as a data store.
This one Azure database for
MySQL and I will use the single server option for this one.
Select a resource group and next,
enter a name like this and
also credentials to log into the server.
A username and a password as well and also confirm the password.
That's it. Now create it.
I'll skip to when it is done.
Here is the MySQL Server.
Before we use it, I need to configure its firewall.
I'll add this firewall rule.
This will let all network traffic through.
In a real world scenario,
you should only allow traffic from
specific IP addresses and I'll
also allow other Azure services to talk with this service.
Save these rules and now this is only the server.
It has no database yet.
I'll create one with the Azure Cloud Shell.
I love this shell as it has the Azure Shield ready to be used.
This commands should do it.
There it goes. That's it.
The server now has a database called Todos for todo items.
Let's go back to Spring Cloud,
because now we can connect
the microservice app to the MySQL database.
We can do that here in surface bindings,
add a new binding and enter a name for the binding.
For the binding type,
I'll pick Azure database for MySQL.
It should load automatically.
This is the server that we
created and this is the database that we need.
I'll enter my username and also my password for
the MySQL server and create a binding. That's it.
The infrastructure is ready.
Now for the application,
here in Visual Studio Code,
I'll use this command.
This is Curl calling a URL from start.spring.io,
which is a websites that you can use to
create starter Spring Boot applications.
Here we go. Let's open the application. Here it is.
This is the basis for the microservice,
and we need to add to it.
First, I'll add a new file here Todo.java.
This will be the todo entity for the microservice.
There we go. Another new file, TodoRepository.java.
This is the repository for the microservice.
Finally, another file TodoController.java.
This is the controller that will do the actual work.
If you look here, you'll see that on initiation,
the controller inserts three todo items into the database.
Now in this properties file,
I need to paste this.
This will automatically create the database when
the application is deployed. That's it.
The app is ready.
Here is a new terminal Window that I will use to
build the app and deploy it to spring apps.
This command uses Maven to build the application.
Let me clean this up.
This command will push the microservice to Azure Spring Cloud.
There it goes. I'll skip to when it is done.
These are the application details again.
It seems to be running fine.
Here is the test endpoint URL.
Let's try it. It worked.
This is JSON data containing
the todo items that the microservice got from the MySQL database.
Cool. Azure Spring Apps enables you to run
Java Spring Boot microservices in the Cloud and
easily connect them to services like Azure Database for MySQL.
Go and check it out.