Overview
Microsoft Azure Spring Apps (ASA) offers a simple, reliable, and scalable way to host your Java Spring applications. ASA frees you from managing the hardware, networking, infrastructure, and containers on which your application is running. All of those things are handled by the platform. ASA also provides simple deployment mechanisms for your code.
In this article, I will show you how to deploy a local Spring application to an Azure Spring App.
Prerequisites
Azure Prerequisites
This article assumes that you already have an Azure Spring Apps Service and an Azure Spring App running under that service. Refer to the following articles for information on how to create these:
When I wrote this article, I created a service named "dgtestasasvc" and an app named "dtestapp", as shown in Fig. 1.
Fig. 1
Local Prerequisites
In order to proceed, you will need to have Java, Maven, and git installed locally. Many IDEs will assist you in installing these. If you are running on a Windows operating system, you should also install [Windows Subsystem for Linux[(https://learn.microsoft.com/en-us/windows/wsl/install).
Sample Code
You are welcome to use your own Spring application. However, if you do not have one available, you can this sample Spring Boot application. It contains a single page that displays the message: "Greetings from Spring Boot!"
Retrieve and build the sample application with the following commands:
git clone -b boot-2.7 https://github.com/spring-guides/gs-spring-boot.git
cd gs-spring-boot/complete
mvn clean package -DskipTests
Deployment
The Azure CLI contains a command to deploy a Spring App to an existing Azure Spring App. The syntax is:
az spring app deploy \
--resource-group \
--service \
--name hellospring \
--artifact-path target/spring-boot-complete-0.0.1-SNAPSHOT.jar
Here is the syntax for my service and app:
az spring app deploy \
--resource-group dgtestasarg \
--service dgtestasasvc \
--name dgtestapp \
--artifact-path target/spring-boot-complete-0.0.1-SNAPSHOT.jar
This deployment may take a couple minutes.
Test the Deployed App
If your application deploys without error, you can view it by opening a web browser and navigating to:
https://ASA Service Name-App-Name.azuremicroservices.io
where:
- ASA Service Name is the name of the Azure Spring App Service
- App-Name is the name of the Azure Spring App
Here is the URL for my deployment:
https://dgtestasasvc-dgtestapp.azuremicroservices.io
The output is shown in Fig. 2.
Fig. 2
Conclusion
In this article, you learned how to deploy a local Spring application to an Azure Spring App.