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 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 article describes the following two options for deploying to Azure Spring Apps:

  • The Azure portal is a more conventional way to create resources and deploy applications step by step. It's suitable for Spring developers who are using Azure cloud services for the first time.
  • The Azure Developer CLI is a more efficient way to automatically create resources and deploy applications through simple commands. It covers application code and infrastructure as code files needed to provision the Azure resources. It's suitable for Spring developers who are familiar with Azure cloud services.

1. Prerequisites

2. Prepare the Spring project

Use the following steps to prepare the project:

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

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

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

    ./mvnw clean package
    
  4. Run the sample project locally by using the following command:

    ./mvnw spring-boot:run
    

3. Prepare the cloud environment

The main resource you need to run this sample is an Azure Spring Apps instance. Use the following steps to create this resource.

3.1. Sign in to the Azure portal

Open your web browser and go to the Azure portal. Enter your credentials to sign in to the portal. The default view is your service dashboard.

3.2. Create an Azure Spring Apps instance

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

  1. Select Create a resource in the corner of the Azure portal.

  2. Select Compute > Azure Spring Apps.

    Screenshot of the Azure portal that shows Azure Spring Apps in the list of compute resources.

  3. Fill out the Basics form with the following information.

    Use the following table as a guide for completing the form. The recommended Plan is Standard consumption & dedicated (preview).

    Setting Suggested value Description
    Subscription Your subscription name The Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you'd like to be billed for the resource.
    Resource group myresourcegroup A new resource group name or an existing one from your subscription.
    Name myasa A unique name that identifies your Azure Spring Apps service. The name must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number.
    Plan Standard consumption & dedicated (preview) The pricing plan determines the resource and cost associated with your instance.
    Region The region closest to your users The location that is closest to your users.
    Container Apps Environment myacaenv The environment is a secure boundary around one or more container apps that can communicate with each other and share a virtual network, logging, and Dapr configuration.

    Screenshot of the Azure portal that shows the Create Azure Spring Apps page.

  4. (Optional) Create a Container Apps Environment.

    1. Fill out the Basics tab with the following information:

      • Environment name: myacaenv
      • Plan: Consumption
      • Zone redundancy: Disabled

      Screenshot of the Azure portal that shows the Create Container Apps Environment with consumption plan selected.

    2. Select Create to create the Container Apps Environment.

  5. Select Review and Create to review your selections. Select Create to provision the Azure Spring Apps instance.

  6. On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. After the deployment is done, you can select Pin to dashboard, which creates a tile for this service on your Azure portal dashboard as a shortcut to the service's Overview page.

    Screenshot of the Azure portal that shows the Notifications pane for Azure Spring Apps creation.

  7. Select Go to resource to go to the Azure Spring Apps Overview page.

4. Deploy the app to Azure Spring Apps

This section provides the steps to deploy your application to Azure Spring Apps.

Use the following steps to deploy using the Maven plugin for Azure Spring Apps:

  1. Navigate to the complete directory, and then run the following command to configure the app in Azure Spring Apps:

    ./mvnw com.microsoft.azure:azure-spring-apps-maven-plugin:1.18.0:config
    

    The following list describes the command interactions:

    • OAuth2 login: You need to authorize the login to Azure based on the OAuth2 protocol.
    • Select subscription: Select the subscription list number of the Azure Spring Apps instance you created, which defaults to the first subscription in the list. If you use the default number, press Enter directly.
    • Select Azure Spring Apps for deployment: Select the list number of the Azure Spring Apps instance you created. If you use the default number, press Enter directly.
    • Input the app name: Provide an app name. If you use the default project artifact ID, press Enter directly.
    • Expose public access for this app (boot-for-azure)?: Press y.
    • Confirm to save all the above configurations (Y/n): Press y. If you press n, the configuration isn't saved in the POM files.
  2. Use the following command to deploy the app:

    ./mvnw com.microsoft.azure:azure-spring-apps-maven-plugin:1.18.0:deploy
    

    The following list describes the command interaction:

    • OAuth2 login: You need to authorize the login to Azure based on the OAuth2 protocol.

    After the command is executed, you can see from the following log messages that the deployment was successful:

    [INFO] Deployment(default) is successfully updated.
    [INFO] Deployment Status: Running
    [INFO]   InstanceName:demo-default-x-xxxxxxxxxx-xxxxx  Status:Running Reason:null       DiscoverStatus:UNREGISTERED
    [INFO] Getting public url of app(demo)...
    [INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-demo.azuremicroservices.io
    

2. Prepare the Spring project

Use the following steps to prepare the project:

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

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

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

    ./mvnw clean package
    
  4. Run the sample project locally by using the following command:

    ./mvnw spring-boot:run
    

3. Prepare the cloud environment

The main resource you need to run this sample is an Azure Spring Apps instance. Use the following steps to create this resource.

3.1. Sign in to the Azure portal

Open your web browser and go to the Azure portal. Enter your credentials to sign in to the portal. The default view is your service dashboard.

3.2. Create an Azure Spring Apps instance

Use the following steps to create a service instance:

  1. Select Create a resource in the corner of the Azure portal.

  2. Select Compute > Azure Spring Apps.

    Screenshot of the Azure portal that shows Azure Spring Apps in the list of compute resources.

  3. Fill out the Basics form with the following information:

    Setting Suggested Value Description
    Subscription Your subscription name The Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you'd like to be billed for the resource.
    Resource group myresourcegroup A new resource group name or an existing one from your subscription.
    Name myasa A unique name that identifies your Azure Spring Apps service. The name must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number.
    Plan Standard The pricing plan that determines the resource and cost associated with your instance.
    Region The region closest to your users The location that is closest to your users.
    Zone Redundant Unselected Indicates whether to create your Azure Spring Apps service in an Azure availability zone. This feature isn't currently supported in all regions.

    Screenshot of the Azure portal that shows the Create Azure Spring Apps page.

  4. Select Review and Create to review your selections. Select Create to provision the Azure Spring Apps instance.

  5. On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. After the deployment is done, you can select Pin to dashboard, which creates a tile for this service on your Azure portal dashboard as a shortcut to the service's Overview page.

    Screenshot of the Azure portal that shows the Notifications pane for Azure Spring Apps creation.

  6. Select Go to resource to go to the Azure Spring Apps Overview page.

4. Deploy the app to Azure Spring Apps

This section provides the steps to deploy your application to Azure Spring Apps.

Use the following steps to deploy using the Maven plugin for Azure Spring Apps:

  1. Navigate to the complete directory, and then run the following command to configure the app in Azure Spring Apps:

    ./mvnw com.microsoft.azure:azure-spring-apps-maven-plugin:1.18.0:config
    

    The following list describes the command interactions:

    • OAuth2 login: You need to authorize the login to Azure based on the OAuth2 protocol.
    • Select subscription: Select the subscription list number of the Azure Spring Apps instance you created, which defaults to the first subscription in the list. If you use the default number, press Enter directly.
    • Select Azure Spring Apps for deployment: Select the list number of the Azure Spring Apps instance you created. If you use the default number, press Enter directly.
    • Input the app name: Provide an app name. If you use the default project artifact ID, press Enter directly.
    • Expose public access for this app (boot-for-azure)?: Press y.
    • Confirm to save all the above configurations (Y/n): Press y. If you press n, the configuration isn't saved in the POM files.
  2. Use the following command to deploy the app:

    ./mvnw com.microsoft.azure:azure-spring-apps-maven-plugin:1.18.0:deploy
    

    The following list describes the command interactions:

    • OAuth2 login: You need to authorize the login to Azure based on the OAuth2 protocol.

    After the command is executed, you can see from the following log messages that the deployment was successful:

    [INFO] Deployment(default) is successfully updated.
    [INFO] Deployment Status: Running
    [INFO]   InstanceName:demo-default-x-xxxxxxxxxx-xxxxx  Status:Running Reason:null       DiscoverStatus:UNREGISTERED
    [INFO] Getting public url of app(demo)...
    [INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-demo.azuremicroservices.io
    

2. Prepare the Spring project

Use the following steps to prepare the project:

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

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

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

    ./mvnw clean package
    
  4. Run the sample project locally by using the following command:

    ./mvnw spring-boot:run
    

3. Prepare the cloud environment

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

3.1. Provide names for each resource

Create variables to hold the resource names by using the following commands. Be sure to replace the placeholders with your own values.

export LOCATION="<region>"
export RESOURCE_GROUP="<resource-group-name>"
export SERVICE_NAME="<Azure-Spring-Apps-instance-name>"
export APP_NAME="demo"

3.2. Create a new resource group

Use the following steps to create a new resource group:

  1. Use the following command to sign in to the Azure CLI:

    az login
    
  2. Use the following command to set the default location:

    az configure --defaults location=${LOCATION}
    
  3. Use the following command to list all available subscriptions to determine the subscription ID to use:

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

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

    az group create --resource-group ${RESOURCE_GROUP}
    
  6. Use the following command to set the newly created resource group as the default resource group:

    az configure --defaults group=${RESOURCE_GROUP}
    

3.3. Install extension and register namespace

Use the following commands to install the Azure Spring Apps extension for the Azure CLI and register the namespace: Microsoft.SaaS:

az extension add --name spring --upgrade
az provider register --namespace Microsoft.SaaS

3.4. Create an Azure Spring Apps instance

Use the following steps to create the service instance:

  1. Use the following command to accept the legal terms and privacy statements for the Enterprise plan:

    Note

    This step is necessary only if your subscription has never been used to create an Enterprise plan instance of Azure Spring Apps.

    az term accept \
        --publisher vmware-inc \
        --product azure-spring-cloud-vmware-tanzu-2 \
        --plan asa-ent-hr-mtr
    
  2. Use the following command to create an Azure Spring Apps service instance:

    az spring create \
        --name ${SERVICE_NAME} \
        --sku Enterprise
    

3.5. 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 that shows the relationship between apps and an Azure Spring Apps service instance.

Use the following command to create the app on Azure Spring Apps:

az spring app create \
    --service ${SERVICE_NAME} \
    --name ${APP_NAME} \
    --assign-endpoint true

4. Deploy the app to Azure Spring Apps

This section provides the steps to deploy your application to Azure Spring Apps.

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

az spring app deploy \
    --service ${SERVICE_NAME} \
    --name ${APP_NAME} \
    --artifact-path target/demo-0.0.1-SNAPSHOT.jar

Deploying the application can take a few minutes.

5. Validate the app

After deployment, you can access the app at https://<your-Azure-Spring-Apps-instance-name>-demo.azuremicroservices.io. When you open the app, you get the response Hello World.

From the navigation pane of the Azure Spring Apps instance overview page, select Logs to check the app's logs.

Screenshot of the Azure portal that shows the Azure Spring Apps Logs page.

Use the following command to check the app's log to investigate any deployment issue:

az spring app logs \
    --service ${SERVICE_NAME} \
    --name ${APP_NAME}

6. Clean up resources

Be sure to delete the resources you created in this article when you no longer need them. To delete the resources, just delete the resource group that contains them. You can delete the resource group using the Azure portal. Alternatively, to delete the resource group by using Azure CLI, use the following command:

az group delete --name ${RESOURCE_GROUP}

You can delete the Azure resource group, which includes all the resources in the resource group.

Use the following steps to delete the entire resource group, including the newly created service:

  1. Locate your resource group in the Azure portal. On the navigation menu, select Resource groups. Then, select the name of your resource group - for example, myresourcegroup.

  2. On your resource group page, select Delete. Enter the name of your resource group in the text box to confirm deletion - for example, myresourcegroup - then, select Delete.

7. Next steps

For more information, see the following articles: