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:
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
- An Azure subscription. If you don't have a subscription, create a free account before you begin.
- Git.
- 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.
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:
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 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. Select Review and Create to review your selections. Then, 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 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 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.
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:
Go to the Azure Spring Apps instance you created, expand Settings in the navigation pane, and then select Apps.
On the Apps pane, select Create App to open the Create App page.
Set App name to football-billboard, select Service Registry on the Bind column, and then select Create.
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.
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:
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.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.
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.
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.
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:
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.
Select View logs to query the logs of the job execution.
Open the public endpoint of the app in a browser window to see the billboard UI. Leave the app open.
Go back to the overview page of the
football
job and select Run to trigger the execution again.Go back to the endpoint page in the browser and select Refresh to see the UI changed, as shown in the following screenshot:
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:
Locate your resource group in the Azure portal. On the navigation menu, select Resource groups, and then select the name of your resource group.
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:
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for