Quickstart: Deploy microservice applications to Azure Spring Apps

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. For more information, see Migrate Azure Spring Apps Standard consumption and dedicated plan 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 Enterprise plan.

Diagram that shows the architecture of the PetClinic sample on the Azure Spring Apps Enterprise plan.

The diagram shows the following architectural flows and relationships of the Pet Clinic sample:

  • Uses Azure Spring Apps to manage the frontend and backend apps. The backend apps are built with Spring Boot and each app uses HSQLDB as the persistent store. The reforged frontend app builds upon Pet Clinic API Gateway App with Node.js serving as a standalone frontend web application.
  • Uses the managed components on Azure Spring Apps, including Service Registry, Application Configuration Service, Spring Cloud Gateway, and Application Live View. The Application Configuration Service reads the Git repository configuration.
  • Exposes the URL of Spring Cloud Gateway to route request to backend service apps, and exposes the URL of the Application Live View to monitor the backend apps.
  • 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 Tanzu Developer Tools exposes public access for Application Live View, which is a risk point. The production environment needs to secure the access. For more information, see the Configure Dev Tools Portal section of Configure Tanzu Dev Tools in the Azure Spring Apps Enterprise plan.

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.

Diagram that shows the architecture of the PetClinic sample 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 option is the easiest and the fastest way to create resources and deploy applications with a single click. This option is suitable for Spring developers who want to quickly deploy applications to Azure cloud services.
  • 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 CLI option uses a powerful command line tool to manage Azure resources. This option is suitable for Spring developers who are familiar with Azure cloud services.
  • 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.

1. Prerequisites

2. Prepare the Spring project

Use the following steps to prepare the sample locally:

  1. Clone the sample project by using the following command:

    git clone https://github.com/Azure-Samples/spring-petclinic-microservices.git
    
  2. Navigate to the project root directory and then use the following command to run the sample project locally:

    bash ./scripts/run_all_without_infra.sh
    
  3. After the script completes successfully, go to http://localhost:8080 in your browser to access the PetClinic application.

3. Prepare the cloud environment

This section describes how to create an Azure Spring Apps service instance and prepare the Azure cloud environment.

3.1. Sign in to the Azure portal

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:

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

  2. On the Azure Services tab, select Compute > Azure Spring Apps.

    Screenshot of the Azure portal that shows the Create a Resource page with Azure Spring Apps highlighted.

  3. On the Create Azure Spring Apps page, fill out the form on the Basics tab.

    Screenshot of the Azure portal that shows the Create Azure Spring Apps page with the Basics tab selected.

    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.
  4. 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.

    Screenshot of the Azure portal that shows the Create Azure Spring Apps page with the Diagnostics tab selected and the Create new button highlighted.

  5. 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.

    Screenshot of the Azure portal that shows the Create Azure Spring Apps page with the Create new Application Insights resource pane showing.

  6. Select Review and Create to review your selections. Then, select Create to provision the Azure Spring Apps instance.

  7. 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.

    Screenshot of the Azure portal that shows a deployment of a resource and the Notification pane with Go to resource and Pin to dashboard buttons.

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

  9. Select Config Server in the navigation pane.

  10. On the Config Server page, for URI, enter https://github.com/Azure-Samples/spring-petclinic-microservices-config.git and then select Validate.

    Screenshot of the Azure portal that shows the Config Server page with the Default URI and the Validate button highlighted.

  11. After validation, select Apply to finish the Config Server configuration.

4. Deploy the apps to Azure Spring Apps

You can now deploy the app to Azure Spring Apps.

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

  1. Navigate to the sample project directory and then use the following command to configure the apps for Azure Spring Apps:

    ./mvnw -P spring-apps com.microsoft.azure:azure-spring-apps-maven-plugin:1.17.0:config
    
  2. 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.
  3. Use the following command to build and deploy each application:

    ./mvnw azure-spring-apps:deploy
    
  4. 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.azuremicroservices.io

...

[INFO] Getting public url of app(api-gateway)...
[INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-api-gateway.azuremicroservices.io

2. Prepare the Spring project

The Deploy to Azure button in the next section launches an Azure portal experience that deploys source code from the Spring PetClinic repository. No local preparation steps are needed.

3. Prepare the cloud environment

The main resource you need to run this sample is an Azure Spring Apps instance. This section describes how to create this resource.

This section uses a Deploy to Azure button to launch a deployment experience in the Azure portal. This experience uses an ARM template to create Azure resources.

3.1. Sign in to the Azure portal

Go to the Azure portal, enter your credentials, and sign in to the portal. The default view is your service dashboard.

3.2. Create Azure resources

Use the following steps to create all the Azure resources that the app depends on:

  1. Select the following Deploy to Azure button to launch the deployment experience in the Azure portal:

    Button to deploy the Resource Manager template to Azure.

  2. Fill out the form on the Basics tab. Use the following table as a guide for completing the form:

    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.
    Region The region closest to your users. The region is used to create the resource group.

    Screenshot of the Azure portal that shows the Custom deployment page.

  3. Select Review and Create to review your selections. Then, select Create to deploy the app to Azure Spring Apps.

  4. On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. After the deployment finishes, 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 open the service's Overview page.

    Screenshot of the Azure portal that shows the Overview page with the custom deployment notifications pane open.

4. Deploy the apps to Azure Spring Apps

The Deploy to Azure button in the previous section launches an Azure portal experience that includes application deployment, so nothing else is needed.

5. Validate the apps

The following sections describe how to validate the deployment.

5.1. Access the applications

After the deployment finishes, you can find the Spring Cloud Gateway URL from the deployment outputs, as shown in the following screenshot:

Screenshot of the Azure portal that shows the Deployment Outputs page.

Open the gateway URL. The application should look similar to the following screenshot:

Screenshot of the PetClinic application running on Azure Spring Apps Enterprise plan.

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:

Screenshot of the Azure portal that shows the Logs page of the query on PetClinic application and the results for the Enterprise plan.

5.3. Monitor the applications

Application Insights monitors the application dependencies, as shown by the following application tracing map:

Screenshot of the Azure portal that shows the Application map page for Azure Spring Apps Enterprise plan.

You can find the Application Live View URL from the deployment outputs. Open the Application Live View URL to monitor application runtimes, as shown in the following screenshot:

Screenshot of the Application Live View for the PetClinic application.

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.azuremicroservices.io. The application should look similar to the following screenshot:

Screenshot of the PetClinic application running on Azure Spring Apps.

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:

Screenshot of the Azure portal that shows the Logs page of the query on PetClinic application and the results.

5.3. Monitor the applications

Application Insights monitors the application dependencies, as shown by the following application tracing map:

Screenshot of the Azure portal that shows the Application map page for an Application Insights instance.

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:

Screenshot of the Spring Boot Admin Server page for the PetClinic application listing the current application instances.

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.

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

  1. Locate your resource group in the Azure portal. On the navigation menu, select Resource groups, and then select the name of your resource group.

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

Be sure to delete the resources you created in this article when you no longer need them. 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:

  1. Locate your resource group in the Azure portal. On the navigation menu, select Resource groups, and then select the name of your resource group.

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

7. Next steps

For more information, see the following articles: