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 (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.
Use the following steps to create an Azure Spring Apps service instance.
Select Open Cloudshell and sign in to your Azure account in Azure Cloud Shell.
az account show
Azure Cloud Shell workspaces are temporary. When first started, the shell prompts you to select an Azure Storage instance with your subscription to persist files across sessions.
After you sign in successfully, use the following command to display a list of your subscriptions.
az account list --output table
Use the following command to set your default subscription.
az account set --subscription <subscription-ID>
Use the following command to create a resource group.
az group create \
--resource-group <name-of-resource-group> \
--location eastus
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>
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. Apps run in an Azure Spring Apps service instance, as shown in the following diagram.
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.
Azure CLI. Install the Azure CLI extension for Azure Spring Apps Standard consumption 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.
Select Open Cloudshell and sign in to your Azure account in Azure Cloud Shell.
az account show
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.
After you sign in successfully, use the following command to display a list of your subscriptions.
az account list --output table
Use the following command to set your default subscription.
az account set --subscription <subscription-ID>
Define variables for this quickstart with the names of your resources and desired settings.
Use the following command to create a resource group.
az group create \
--resource-group ${RESOURCE_GROUP} \
--location ${LOCATION}
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. To create the environment, run the following command:
Use the following command to create a variable to store the environment resource ID:
MANAGED_ENV_RESOURCE_ID=$(az containerapp env show \
--name ${MANAGED_ENVIRONMENT} \
--resource-group ${RESOURCE_GROUP} \
--query id \
--output tsv)
Use the following command to create an Azure Spring Apps service instance. The Azure Spring Apps Standard consumption plan instance 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. Apps run in an Azure Spring Apps service instance, or simply service instance, as shown in the following diagram.
Use the following command to specify the app name on Azure Spring Apps and to allocate required resources:
Use Spring Initializr to generate a sample project with recommended dependencies for Azure Spring Apps. The following URL provides default settings for you.
The following image shows the recommended Initializr settings for the hellospring sample project.
This example uses Java version 11. To use a different Java version, change the Java version setting under Project Metadata.
When all dependencies are set, select Generate.
Download and unpack the package, and then create a web controller for your web application by adding the file src/main/java/com/example/hellospring/HelloController.java with the following contents:
package com.example.hellospring;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Greetings from Azure Spring Apps!";
}
}
Create an instance of Azure Spring Apps
Use the following steps to create an instance of Azure Spring Apps using the Azure portal.
From the top search box, search for Azure Spring Apps.
Select Azure Spring Apps from the results.
On the Azure Spring Apps page, select Create.
Fill out the form on the Azure Spring Apps Create page. Consider the following guidelines:
Subscription: Select the subscription you want to be billed for this resource.
Resource group: Creating new resource groups for new resources is a best practice.
Service Name: Specify the service instance name. You use this name later in this article where the <Azure-Spring-Apps-instance-name> placeholder appears. 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.
Region: Select the region for your service instance.
Select Review and create.
Import the project
Use the following steps to import the project.
Open IntelliJ IDEA, and then select Open.
In the Open File or Project dialog box, select the hellospring folder.
Build and deploy your app
Note
To run the project locally, add spring.config.import=optional:configserver: to the project's application.properties file.
Use the following steps to build and deploy your app.
In the App textbox, select the plus sign (+) to create a new app.
In the App name: textbox under App Basics, enter hellospring, and then select the More settings check box.
Select the Enable button next to Public endpoint. The button changes to Disable <to be enabled>.
If you're using Java 11, select Java 11 for the Runtime option.
Select OK.
Under Before launch, select Run Maven Goal 'hellospring:package', and then select the pencil icon to edit the command line.
In the Command line textbox, enter -DskipTests after package, and then select OK.
To start the deployment, select the Run button at the bottom of the Deploy Azure Spring Apps app dialog box. The plug-in runs the command mvn package -DskipTests on the hellospring app and deploys the .jar file generated by the package command.
Deploy a Spring Boot web app to Azure Spring Apps with Visual Studio Code
To deploy a Spring Boot web app to Azure Spring Apps, follow the steps in Java on Azure Spring Apps.
Once deployment has completed, 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.