Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
The Basic, Standard plans entered a retirement period on March 17, 2025. For more information, see the Azure Spring Apps retirement announcement.
The Standard consumption and dedicated plan entered a retirement period on September 30, 2024, with a complete shutdown by the end of March 2025.
This article explains how to build and deploy Spring applications to Azure Spring Apps. You can use Azure CLI, the Maven plugin, or IntelliJ. This article describes each alternative.
Prerequisites
- Completion of the previous quickstarts in this series:
- JDK 17
- Maven 3.0 or above
- An Azure subscription. If you don't have a subscription, create a Trial before you begin.
- Optionally, Azure CLI version 2.45.0 or higher. Install the Azure Spring Apps extension with the following command:
az extension add --name spring - Optionally, the Azure Toolkit for IntelliJ.
Build the Spring applications locally
Use the following commands to clone the sample repository, navigate to the sample folder, and then build the project.
git clone https://github.com/azure-samples/spring-petclinic-microservices
cd spring-petclinic-microservices
mvn clean package -DskipTests -Denv=cloud
Compiling the project takes 5-10 minutes. When the project is compiled, you should have individual JAR files for each service in their respective folders.
Create and deploy apps on Azure Spring Apps
Use the following steps to create and deploys apps on Azure Spring Apps using the CLI.
If you didn't run the following commands in the previous quickstarts, run them now to set the CLI defaults.
az configure --defaults group=<resource-group-name> spring=<service-name>Create the two core Spring applications for PetClinic:
api-gatewayandcustomers-service.az spring app create \ --name api-gateway \ --runtime-version Java_17 \ --instance-count 1 \ --memory 2Gi \ --assign-endpoint az spring app create \ --name customers-service \ --runtime-version Java_17 \ --instance-count 1 \ --memory 2GiDeploy the JAR files built in the previous step.
az spring app deploy \ --name api-gateway \ --artifact-path spring-petclinic-api-gateway/target/api-gateway-3.0.1.jar \ --jvm-options="-Xms2048m -Xmx2048m" az spring app deploy \ --name customers-service \ --artifact-path spring-petclinic-customers-service/target/customers-service-3.0.1.jar \ --jvm-options="-Xms2048m -Xmx2048m"Query the app status after deployments with the following command.
az spring app list --output tableThis command produces output similar to the following example:
Name Location ResourceGroup Production Deployment Public Url Provisioning Status CPU Memory Running Instance Registered Instance Persistent Storage ----------------- ---------- --------------- ----------------------- --------------------------------------------------- --------------------- ----- -------- ------------------ --------------------- -------------------- api-gateway chinanorth2 xxxxxx-sp default https://<service name>-api-gateway.microservices.azure.cn Succeeded 1 2 1/1 1/1 - customers-service chinanorth2 <service name> default Succeeded 1 2 1/1 1/1 -
Verify the services
Access api-gateway and customers-service from a browser with the Public Url shown previously, in the format of https://<service name>-api-gateway.microservices.azure.cn.
Tip
To troubleshot deployments, you can use the following command to get logs streaming in real time whenever the app is running az spring app logs --name <app name> --follow.
Deploy extra apps
To get the PetClinic app functioning with all features like Admin Server, Visits, and Veterinarians, deploy the other apps with following commands:
az spring app create \
--name admin-server \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi \
--assign-endpoint
az spring app create \
--name vets-service \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi
az spring app create \
--name visits-service \
--runtime-version Java_17 \
--instance-count 1 \
--memory 2Gi
az spring app deploy \
--name admin-server \
--runtime-version Java_17 \
--artifact-path spring-petclinic-admin-server/target/admin-server-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
az spring app deploy \
--name vets-service \
--runtime-version Java_17 \
--artifact-path spring-petclinic-vets-service/target/vets-service-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
az spring app deploy \
--name visits-service \
--runtime-version Java_17 \
--artifact-path spring-petclinic-visits-service/target/visits-service-3.0.1.jar \
--jvm-options="-Xms1536m -Xmx1536m"
Clean up resources
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:
echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."