Quickstart: Build and deploy apps to Azure Spring Apps

Note

The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.

The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps.

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

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.

  1. 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>
    
  2. Create the two core Spring applications for PetClinic: api-gateway and customers-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 2Gi
    
  3. Deploy 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"
    
  4. Query the app status after deployments with the following command.

    az spring app list --output table
    

    This 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.

Screenshot of the PetClinic sample app that shows the Owners page.

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"