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
- An Azure subscription. If you don't have an Azure subscription, create an Azure free account before you begin.
- Git.
- Java Development Kit (JDK), version 17.
- An Azure subscription. If you don't have an Azure subscription, create an Azure free account before you begin.
- If you're deploying an Azure Spring Apps Enterprise plan instance for the first time in the target subscription, see the Requirements section of Enterprise plan in Azure Marketplace.
- Git.
- Java Development Kit (JDK), version 17.
- Azure CLI version 2.45.0 or higher.
2. Prepare the Spring project
Use the following steps to prepare the project:
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
Use the following command to move to the project folder:
cd gs-spring-boot-for-azure/complete
Use the following Maven command to build the project:
./mvnw clean package
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:
Select Create a resource in the corner of the Azure portal.
Select Compute > Azure Spring Apps.
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. (Optional) Create a Container Apps Environment.
Select Review and Create to review your selections. Select Create to provision the Azure Spring Apps instance.
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.
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:
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.
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:
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
Use the following command to move to the project folder:
cd gs-spring-boot-for-azure/complete
Use the following Maven command to build the project:
./mvnw clean package
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:
Select Create a resource in the corner of the Azure portal.
Select Compute > Azure Spring Apps.
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. Select Review and Create to review your selections. Select Create to provision the Azure Spring Apps instance.
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.
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:
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.
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:
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
Use the following command to move to the project folder:
cd gs-spring-boot-for-azure/complete
Use the following Maven command to build the project:
./mvnw clean package
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:
Use the following command to sign in to the Azure CLI:
az login
Use the following command to set the default location:
az configure --defaults location=${LOCATION}
Use the following command to list all available subscriptions to determine the subscription ID to use:
az account list --output table
Use the following command to set the default subscription:
az account set --subscription <subscription-ID>
Use the following command to create a resource group:
az group create --resource-group ${RESOURCE_GROUP}
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:
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
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.
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.
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:
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.
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:
Feedback
Submit and view feedback for