Quickstart: Deploy your first application to Azure Spring Apps

Note

The first 50 vCPU hours and 100 GB hours of memory are free each month. For more information, see Price Reduction - Azure Spring Apps does more, costs less! on the Apps on Azure Blog.

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

This article applies to: ✔️ Standard consumption and dedicated (Preview) ✔️ Basic/Standard ✔️ Enterprise

This article explains how to deploy a small application to run on Azure Spring Apps.

The application code used in this tutorial is a simple app. When you've completed this example, the application is accessible online, and you can manage it through the Azure portal.

This quickstart explains how to:

  • Generate a basic Spring project.
  • Provision a service instance.
  • Build and deploy an app with a public endpoint.
  • Clean up the resources.

At the end of this quickstart, you have a working Spring app running on Azure Spring Apps.

Prerequisites

  • An Azure subscription. If you don't have a subscription, create a free account before you begin.
  • Apache Maven

  • Azure CLI. Install the Azure CLI extension for Azure Spring Apps Standard consumption and dedicated plan by using the following command:

    az extension remove --name spring && \
    az extension add --name spring
    
  • Use the following commands to install the Azure Container Apps extension for the Azure CLI and register these namespaces: Microsoft.App, Microsoft.OperationalInsights, and Microsoft.AppPlatform:

    az extension add --name containerapp --upgrade
    az provider register --namespace Microsoft.App
    az provider register --namespace Microsoft.OperationalInsights
    az provider register --namespace Microsoft.AppPlatform
    

Provision an instance of Azure Spring Apps

Use the following steps to create an Azure Spring Apps service instance.

  1. Select Open Cloudshell and sign in to your Azure account in Azure Cloud Shell.

    az account show
    
  2. Azure Cloud Shell workspaces are temporary. When first started, the shell prompts you to associate an Azure Storage instance with your subscription to persist files across sessions. For more information, see Introduction to Azure Storage.

    Screenshot of an Azure portal alert that no storage is mounted in the Azure Cloud Shell.

  3. After you sign in successfully, use the following command to display a list of your subscriptions:

    az account list --output table
    
  4. Use the following command to set your default subscription:

    az account set --subscription <subscription-ID>
    
  5. Use the following commands to define variables for this quickstart with the names of your resources and desired settings:

    LOCATION="<region>"
    RESOURCE_GROUP="<resource-group-name>"
    MANAGED_ENVIRONMENT="<Azure-Container-Apps-environment-name>"
    SERVICE_NAME="<Azure-Spring-Apps-instance-name>"
    APP_NAME="<Spring-app-name>"
    
  6. Use the following command to create a resource group:

    az group create \
        --resource-group ${RESOURCE_GROUP} \
        --location ${LOCATION}
    
  7. An Azure Container Apps environment creates a secure boundary around a group of applications. Apps deployed to the same environment are deployed in the same virtual network and write logs to the same log analytics workspace. For more information, see Log Analytics workspace overview. Use the following command to create the environment:

    az containerapp env create \
        --resource-group ${RESOURCE_GROUP} \
        --name ${MANAGED_ENVIRONMENT} \
        --location ${LOCATION} \
        --enable-workload-profiles
    
  8. Use the following command to create a variable to store the environment resource ID:

    MANAGED_ENV_RESOURCE_ID=$(az containerapp env show \
        --resource-group ${RESOURCE_GROUP} \
        --name ${MANAGED_ENVIRONMENT} \
        --query id \
        --output tsv)
    
  9. Use the following command to create an Azure Spring Apps service instance. An instance of the Azure Spring Apps Standard consumption and dedicated plan is built on top of the Azure Container Apps environment. Create your Azure Spring Apps instance by specifying the resource ID of the environment you created.

    az spring create \
        --resource-group ${RESOURCE_GROUP} \
        --name ${SERVICE_NAME} \
        --managed-environment ${MANAGED_ENV_RESOURCE_ID} \
        --sku standardGen2 \
        --location ${LOCATION}
    

Create an app in your Azure Spring Apps instance

An App is an abstraction of one business app. For more information, see App and deployment in Azure Spring Apps. Apps run in an Azure Spring Apps service instance, as shown in the following diagram.

Diagram showing the relationship between apps and an Azure Spring Apps service instance.

You can create an app in either standard consumption or dedicated workload profiles.

Important

The consumption workload profile has a pay-as-you-go billing model with no starting cost. You're billed for the dedicated workload profile based on the provisioned resources. For more information, see Workload profiles in Consumption + Dedicated plan structure environments in Azure Container Apps (preview) and Azure Spring Apps pricing.

Create an app with consumption workload profile

Use the following command to specify the app name on Azure Spring Apps and to allocate required resources:

az spring app create \
    --resource-group ${RESOURCE_GROUP} \
    --service ${SERVICE_NAME} \
    --name ${APP_NAME} \
    --cpu 1 \
    --memory 2Gi \
    --min-replicas 2 \
    --max-replicas 2 \
    --assign-endpoint true

Azure Spring Apps creates an empty welcome application and provides its URL in the field named properties.url.

Screenshot of the welcome page for a Spring app in an Azure Spring Apps instance.

Create an app with dedicated workload profile

Dedicated workload profiles support running apps with customized hardware and increased cost predictability.

Use the following command to create a dedicated workload profile:

az containerapp env workload-profile set \
    --resource-group ${RESOURCE_GROUP} \
    --name ${MANAGED_ENVIRONMENT} \
    --workload-profile-name my-wlp \
    --workload-profile-type D4 \
    --min-nodes 1 \
    --max-nodes 2

Then, use the following command to create an app with the dedicated workload profile:

az spring app create \
   --resource-group ${RESOURCE_GROUP} \
   --service ${SERVICE_NAME} \
   --name ${APP_NAME} \
   --cpu 1 \
   --memory 2Gi \
   --min-replicas 2 \
   --max-replicas 2 \
   --assign-endpoint true \
   --workload-profile my-wlp

Clone and build the Spring Boot sample project

Use the following steps to clone the Spring Boot sample project.

  1. Use the following command to clone the Spring Boot sample project from GitHub.

    git clone -b boot-2.7 https://github.com/spring-guides/gs-spring-boot.git
    
  2. Use the following command to move to the project folder:

    cd gs-spring-boot/complete
    
  3. Use the following Maven command to build the project.

    mvn clean package -DskipTests
    

Deploy the local app to Azure Spring Apps

Use the following command to deploy the .jar file for the app:

az spring app deploy \
    --resource-group ${RESOURCE_GROUP} \
    --service ${SERVICE_NAME} \
    --name ${APP_NAME} \
    --artifact-path target/spring-boot-complete-0.0.1-SNAPSHOT.jar \
    --env testEnvKey=testEnvValue \
    --runtime-version Java_11 \
    --jvm-options '-Xms1024m -Xmx2048m'

Deploying the application can take a few minutes.

  • Apache Maven
  • Azure CLI. Install the Azure Spring Apps extension with the following command: az extension add --name spring

Provision an instance of Azure Spring Apps

Use the following steps to create an Azure Spring Apps service instance.

  1. Select Open Cloudshell and sign in to your Azure account in Azure Cloud Shell.

    az account show
    
  2. Azure Cloud Shell workspaces are temporary. When first started, the shell prompts you to associate an Azure Storage instance with your subscription to persist files across sessions. For more information, see Introduction to Azure Storage.

    Screenshot of an Azure portal alert that no storage is mounted in the Azure Cloud Shell.

  3. After you sign in successfully, use the following command to display a list of your subscriptions:

    az account list --output table
    
  4. Use the following command to set your default subscription:

    az account set --subscription <subscription-ID>
    
  5. Use the following command to create a resource group:

    az group create \
        --resource-group <name-of-resource-group> \
        --location eastus
    
  6. Use the following command to create an Azure Spring Apps service instance:

    az spring create \
        --resource-group <name-of-resource-group> \
        --name <Azure-Spring-Apps-instance-name>
    
  7. Select Y to install the Azure Spring Apps extension and run it.

Create an app in your Azure Spring Apps instance

An App is an abstraction of one business app. For more information, see App and deployment in Azure Spring Apps. Apps run in an Azure Spring Apps service instance, as shown in the following diagram.

Diagram showing the relationship between apps and an Azure Spring Apps service instance.

Use the following command to specify the app name on Azure Spring Apps as hellospring:

az spring app create \
    --resource-group <name-of-resource-group> \
    --service <Azure-Spring-Apps-instance-name> \
    --name hellospring \
    --assign-endpoint true

Clone and build the Spring Boot sample project

Use the following steps to clone the Spring Boot sample project.

  1. Use the following command to clone the Spring Boot sample project from GitHub.

    git clone -b boot-2.7 https://github.com/spring-guides/gs-spring-boot.git
    
  2. Use the following command to move to the project folder:

    cd gs-spring-boot/complete
    
  3. Use the following Maven command to build the project.

    mvn clean package -DskipTests
    

Deploy the local app to Azure Spring Apps

Use the following command to deploy the .jar file for the app (target/spring-boot-complete-0.0.1-SNAPSHOT.jar on Windows):

az spring app deploy \
    --resource-group <name-of-resource-group> \
    --service <Azure-Spring-Apps-instance-name> \
    --name hellospring \
    --artifact-path target/spring-boot-complete-0.0.1-SNAPSHOT.jar

Deploying the application can take a few minutes. After deployment, you can access the app at https://<service-instance-name>-hellospring.azuremicroservices.io/.

Clean up resources

If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When you no longer need the resources, delete them by deleting the resource group. Use the following commands to delete the resource group:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

Next steps

In this quickstart, you learned how to build and deploy a Spring app in an Azure Spring Apps service instance. You also learned how to deploy an app with a public endpoint, and how to clean up resources.

You have access to powerful logs, metrics, and distributed tracing capability from the Azure portal. For more information, see Quickstart: Monitoring Azure Spring Apps apps with logs, metrics, and tracing.

To learn how to use more Azure Spring capabilities, advance to the quickstart series that deploys a sample application to Azure Spring Apps:

To learn how to create a Standard consumption and dedicated plan in Azure Spring Apps for app deployment, advance to the Standard consumption and dedicated quickstart series:

For a packaged app template with Azure Spring Apps infrastructure provisioned using Bicep, see Spring Boot PetClinic Microservices Application Deployed to Azure Spring Apps.

More samples are available on GitHub: Azure Spring Apps Samples.