Quickstart: Deploy your first Spring Batch 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 quickstart shows how to deploy a Spring Batch ephemeral application to Azure Spring Apps. The sample project is derived from the Spring Batch sample Football Job. It's a statistics loading job. In the original sample, a unit test triggers the job. In the adapted sample, the main method of FootballJobApplication initiates the job.

This article applies to: ❌ Basic/Standard ✔️ Enterprise

The following diagram shows the architecture of the system:

Diagram that shows the sample app architecture.

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

1. Prerequisites

2. Prepare the Spring project

Use the following command to clone the sample project from GitHub:

git clone https://github.com/Azure-Samples/azure-spring-apps-samples.git

3. Prepare the cloud environment

The main resource required to run this sample is an Azure Spring Apps instance. This section provides the steps to create this resource.

3.1. Sign in to the Azure portal

Go to the Azure portal and 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.

  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 Enterprise 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 The option to create your Azure Spring Apps service in an Azure availability zone. This feature isn't currently supported in all regions.
    Software IP plan Pay-as-You-Go The pricing plan that lets you pay as you go with Azure Spring Apps.
    Terms Selected The agreement checkbox associated with Marketplace offering. You're required to select this checkbox.
    Deploy sample project Unselected The option to use the built-in sample application.
  4. Select Review and Create to review your selections. Then, 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 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.

    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.

3.3. Enable service registry

Go to the Azure Spring Apps instance you created, expand Managed components in the navigation pane, and then select Service Registry. Then, on the Overview page, select Manage to open the Manage page, select Enable Service Registry, and then select Apply.

Screenshot of the Azure portal that shows the Service Registry page with the Manage pane open and the Enable Service Registry option highlighted.

3.4. Set up a log analytics workspace

For information on querying the data in logs, see Quickstart: Set up a Log Analytics workspace.

4. Deploy the football-billboard app to Azure Spring Apps

Use the following steps to deploy the app:

  1. Go to the Azure Spring Apps instance you created, expand Settings in the navigation pane, and then select Apps.

  2. On the Apps pane, select Create App to open the Create App page.

  3. Set App name to football-billboard, select Service Registry on the Bind column, and then select Create.

    Screenshot of the Azure portal that shows the Create App page with the App name and Bind fields highlighted.

  4. After creating the app, select Deploy App and copy the Azure CLI command for deploying the app. Then, open a Bash window and paste the command onto the command line, replacing the artifact path with the correct value for your system. Then, run the command. Wait several minutes until the build and deployment succeed. The command and output should look similar to the following example:

    $ az spring app deploy -s job-demo -g job-demo -n football-billboard --artifact-path target/spring-batch-football-billboard-0.0.1-SNAPSHOT.jar
    This command usually takes minutes to run. Add '--verbose' parameter if needed.
    [1/5] Requesting for upload URL.
    [2/5] Uploading package to blob.
    [3/5] Creating or Updating build 'football-billboard'.
    [4/5] Waiting for building container image to finish. This may take a few minutes.
    
  5. After deployment, go back to the Apps pane and select the football-billboard app. Then, go to the overview page and select Assign endpoint to expose the public endpoint for the app.

5. Deploy the job sample to Azure Spring Apps

This section provides the steps to deploy the sample.

5.1. Create and execute the job

Use the following steps to create and execute the job:

  1. Navigate to Jobs pane then select Create Job. Fill in the job name as football. Configure the job parameters, such as parallelism, retry limit, and timeout. Add environment variables and secret environment variables as needed. After confirmation, select Create.

    Screenshot of the Azure portal that shows the Jobs (preview) page with the Create Job pane open.

  2. After creating the job, expand Managed components in the navigation pane and select Service Registry. Then, select Job binding, select Bind job to select the football job, and then select Apply to bind.

    Screenshot of the Azure portal that shows the Service Registry page with the Bind job dialog box open.

  3. Go back to the Jobs pane after binding the job, select Deploy Job, and then copy the Azure CLI command for deploying the job. Then, open a Bash window and paste the command onto the command line, replacing the artifact path with the correct value for your system. Then, run the command. Wait several minutes until the build and deployment succeed. The command and output should look similar to the following example:

    $ az spring job deploy -s job-demo -g job-demo -n football --artifact-path target/spring-batch-football-0.0.1-SNAPSHOT-jar-with-dependencies.jar --build-env BP_JVM_VERSION=17
    This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
    This command usually takes minutes to run. Add '--verbose' parameter if needed.
    [1/5] Requesting for upload URL.
    [2/5] Uploading package to blob.
    [3/5] Creating or Updating build 'football'.
    [4/5] Waiting for building container image to finish. This may take a few minutes.
    
  4. After deployment, open the overview page of the football job by selecting the job name. Select Run to initiate the task execution. You can customize each execution of the job with different parameters, such as environment variables, or just select Run to trigger the execution. A message indicates that the job is running.

    Screenshot of the Azure portal that shows the Jobs (preview) Overview page with the Run Job pane open.

6. Check the job execution result and the billboard UI

You can now access the execution of the job and check its result.

Use the following steps to validate:

  1. On the Executions pane, check the job execution result. Wait a few seconds and refresh to see the status turn to Completed. This value means that the job execution finishes successfully.

  2. Select View logs to query the logs of the job execution.

    Screenshot of the Azure portal that shows the Logs page.

  3. Open the public endpoint of the app in a browser window to see the billboard UI. Leave the app open.

    Screenshot of the sample app billboard UI.

  4. Go back to the overview page of the football job and select Run to trigger the execution again.

  5. Go back to the endpoint page in the browser and select Refresh to see the UI changed, as shown in the following screenshot:

    Screenshot of the sample app billboard UI after it changes.

7. Clean up resources

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

8. Next steps

For more information, see the following articles: