Quickstart: Deploy microservice applications to Azure Spring Apps
Article
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 deploy microservice applications to Azure Spring Apps using the well-known sample app PetClinic.
The Pet Clinic sample demonstrates the microservice architecture pattern. The following diagram shows the architecture of the PetClinic application on the Azure Spring Apps Standard plan.
The diagram shows the following architectural flows and relationships of the Pet Clinic sample:
Uses Azure Spring Apps to manage the Spring Boot apps. Each app uses HSQLDB as the persistent store.
Uses the managed components Spring Cloud Config Server and Eureka Service Registry on Azure Spring Apps. The Config Server reads the Git repository configuration.
Exposes the URL of API Gateway to load balance requests to service apps, and exposes the URL of the Admin Server to manage the applications.
Analyzes logs using the Log Analytics workspace.
Monitors performance with Application Insights.
Note
This article uses a simplified version of PetClinic, using an in-memory database that isn't production-ready to quickly deploy to Azure Spring Apps.
The deployed app admin-server exposes public access, which is a risk point. The production environment needs to secure the Spring Boot Admin application.
This article provides the following options for deploying to Azure Spring Apps:
The Azure portal + Maven plugin option is a more conventional way to create resources and deploy applications step by step. This option is suitable for Spring developers using Azure cloud services for the first time.
The Azure Developer CLI option is a more efficient way to automatically create resources and deploy applications through simple commands. The Azure Developer CLI uses a template to provision the Azure resources needed and to deploy the application code. This option is suitable for Spring developers who are familiar with Azure cloud services.
The following list describes the command interaction:
Enter a new environment name: Provide an environment name, which is used as a suffix for the resource group that is created to hold all Azure resources. This name should be unique within your Azure subscription.
The console outputs messages similar to the following example:
Initializing a new project (azd init)
Downloading template code to: <your-local-path>
(✓) Done: Initialized git repository
Enter a new environment name: <your-env-name>
SUCCESS: New project initialized!
You can view the template code in your directory: <your-local-path>
Learn more about running 3rd party code on our DevHub: https://aka.ms/azd-third-party-code-notice
3. Prepare the cloud environment
This section describes how to create an Azure Spring Apps service instance and prepare the Azure cloud environment.
Go to the Azure portal, enter your credentials, and 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 the service instance:
Select Create a resource in the corner of the Azure portal.
On the Azure Services tab, select Compute > Azure Spring Apps.
On the Create Azure Spring Apps page, fill out the form on the Basics tab.
Use the following table as a guide for completing the form. The recommended Plan is Standard.
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 for 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 instance. 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 determines the resources and cost associated with your instance.
Region
The region closest to your users.
The location that is closest to your users.
Zone Redundant
Unselected
Creates your Azure Spring Apps service in an Azure availability zone. Not currently supported in all regions.
Navigate to the Diagnostic settings tab on the Create Azure Spring Apps page and then select Create new to create a new Log Analytics workspaces instance. On the Create new Log Analytics workspace page, update the name of the Log Analytics workspace as needed, and then select OK to confirm the creation.
Navigate to the Application Insights tab on the Create Azure Spring Apps page and then select Create new to create a new Application Insights instance. On the Create new Application Insights resource page, update the Application insights name as needed, select Workspace-based for Resource mode, and then select OK to confirm the creation.
Select Review and Create to review your selections. Then, select Create to provision the Azure Spring Apps instance.
Select the Notifications icon (a bell) to monitor the deployment process. After the deployment finishes, you can select Pin to dashboard to create a shortcut on your Azure portal dashboard to the service's Overview page.
Select Go to resource to go to the Azure Spring Apps Overview page.
After validation, select Apply to finish the Config Server configuration.
Use the following steps to create the required resources:
Use the following command to sign in to Azure with OAuth2. Ignore this step if you already signed in.
azd auth login
The console outputs messages similar to the following example:
Logged in to Azure.
Use the following command to package a deployable copy of your application, provision the template's infrastructure to Azure, and then deploy the application code to those newly provisioned resources:
azd provision
The following list describes the command interactions:
Select an Azure Subscription to use: Use arrows to move, type to filter, then press Enter.
Select an Azure location to use: Use arrows to move, type to filter, then press Enter.
The console outputs messages similar to the following example:
SUCCESS: Your application was provisioned in Azure in xx minutes xx seconds.
You can view the resources created under the resource group rg-<your-environment-name> in Azure Portal:
https://portal.azure.cn/#@/resource/subscriptions/<your-subscription-id>/resourceGroups/rg-<your-environment-name>/overview
Note
This command may take a while to complete. You're shown a progress indicator as it provisions Azure resources.
The following list describes the command interactions:
Select child modules to configure(input numbers separated by comma, eg: [1-2,4,6], ENTER to select ALL): Press Enter to select all.
OAuth2 login: Authorize the sign in 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.
Select apps to expose public access:(input numbers separated by comma, eg: [1-2,4,6], ENTER to select NONE): Enter 1,5 for admin-server and api-gateway.
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 build and deploy each application:
./mvnw azure-spring-apps:deploy
For the OAuth2 login prompt, authorize the login to Azure based on the OAuth2 protocol.
Note
Deployment to Azure Spring Apps can take up to 25 minutes.
After the command runs, a log displays output similar to the following example, which indicates that all deployments are successful:
[INFO] Deployment(default) is successfully updated.
[INFO] Deployment Status: Running
[INFO] InstanceName:admin-server-default-xx-xx-xxx Status:Running Reason:null DiscoverStatus:UP
[INFO] Getting public url of app(admin-server)...
[INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-admin-server.microservices.azure.cn
...
[INFO] Getting public url of app(api-gateway)...
[INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-api-gateway.microservices.azure.cn
Use the following steps to package the app, provision the Azure resources required by the web application, and then deploy to Azure Spring Apps:
Use the following command to package a deployable copy of your application:
azd package
The console outputs messages similar to the following example:
SUCCESS: Your application was packaged for Azure in xx minutes xx seconds.
Use the following command to deploy the application code to those newly provisioned resources:
azd deploy
The console outputs messages similar to the following example:
Deploying services (azd deploy)
(✓) Done: Deploying service admin-server
- Endpoint: https://<your-Azure-Spring-Apps-instance-name>-admin-server.microservices.azure.cn
(✓) Done: Deploying service api-gateway
- Endpoint: https://<your-Azure-Spring-Apps-instance-name>-api-gateway.microservices.azure.cn
(✓) Done: Deploying service customers-service
- No endpoints were found
(✓) Done: Deploying service vets-service
- No endpoints were found
(✓) Done: Deploying service visits-service
- No endpoints were found
SUCCESS: Your application was deployed to Azure in xx minutes xx seconds.
You can view the resources created under the resource group rg-<your-environment-name> in Azure Portal:
https://portal.azure.cn/#@/resource/subscriptions/<your-subscription-id>/resourceGroups/rg-<your-environment-name>/overview
Note
You can also use azd up to combine the previous three commands: azd package (packages a deployable copy of your application), azd provision (provisions Azure resources), and azd deploy (deploys application code). For more information, see Azure-Samples/spring-petclinic-microservices.
5. Validate the apps
The following sections describe how to validate the deployment.
5.1. Access the applications
Using the URL information in the deployment log output, open the URL exposed by the app named api-gateway - for example, https://<your-Azure-Spring-Apps-instance-name>-api-gateway.microservices.azure.cn. The application should look similar to the following screenshot:
5.2. Query the application logs
After you browse each function of the Pet Clinic, the Log Analytics workspace collects logs of each application. You can check the logs by using custom queries, as shown in the following screenshot:
5.3. Monitor the applications
Application Insights monitors the application dependencies, as shown by the following application tracing map:
Open the URL exposed by the app admin-server to manage the applications through the Spring Boot Admin Server, as shown in the following screenshot:
6. 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, you can clean up unnecessary resources to avoid Azure charges.