Skip to content

Latest commit

 

History

History
194 lines (124 loc) · 7.02 KB

File metadata and controls

194 lines (124 loc) · 7.02 KB
author karlerickson
ms.author v-shilichen
ms.service azure-spring-apps
ms.topic include
ms.date 08/19/2025
ms.update-cycle 1095-days

2. Prepare the Spring project

The Deploy to Azure button in the next section launches an Azure portal experience that downloads a JAR package from the spring-cloud-azure-tools releases page on GitHub. No local preparation steps are needed.

[!INCLUDE prepare-spring-project]

Use the following steps to initialize the application from the Azure Developer CLI templates.

  1. Open a terminal, create an empty folder, and then change directory to it.

  2. Use the following command to initialize the project:

    azd init --template spring-guides/gs-spring-boot-for-azure

    The following list describes the command interactions:

    • OAuth2 login: You need to authorize the sign in to Azure based on the OAuth2 protocol.
    • Please enter a new environment name: Provide an environment name, which is used as a suffix for the resource group 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)
    
    (✓) Done: Initialized git repository
    (✓) Done: Downloading template code to: <your-local-path>
    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.

[!INCLUDE hello-prepare-cloud-environment-standard-azure-portal]

3.1. Sign in to the Azure portal

Open your web browser and go to the Azure portal. Enter your credentials to sign in to the portal. The default view is your service dashboard.

3.2. Create an Azure Spring Apps instance

[!INCLUDE provision-basic-azure-spring-apps]

Use the following steps to create the required resources:

  1. 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.
    
  2. Use the following command to set the template using the Standard plan:

    azd env set PLAN standard
  3. 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 ones in 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>-<random-string>> in Azure portal:
    https://portal.azure.com/#@/resource/subscriptions/<your-subscription-id>/resourceGroups/rg-<your-environment-name>/overview
    

    [!NOTE] This may take a while to complete. You see a progress indicator as it provisions Azure resources.


4. Deploy the app to Azure Spring Apps

[!INCLUDE deploy-hello-app-azure-portal]

[!INCLUDE hello-spring-apps-maven-plugin]

  1. Use the following command to deploy the app:

    ./mvnw azure-spring-apps:deploy

    The following list describes the command interaction:

    • OAuth2 login: You need to authorize the sign in to Azure based on the OAuth2 protocol.

    After the command is executed, you can see from the following log messages that the deployment was successful:

    [INFO] Deployment(default) is successfully created
    [INFO] Starting Spring App after deploying artifacts...
    [INFO] Deployment Status: Running
    [INFO]   InstanceName:demo-default-x-xxxxxxxxxx-xxxxx  Status:Running Reason:null       DiscoverStatus:UNREGISTERED
    [INFO]   InstanceName:demo-default-x-xxxxxxxxx-xxxxx  Status:Terminating Reason:null       DiscoverStatus:UNREGISTERED
    [INFO] Getting public url of app(demo)...
    [INFO] Application url: https://<your-Azure-Spring-Apps-instance-name>-demo.azuremicroservices.io
    

Use the following steps to package the app, provision the Azure resources required by the web application, and then deploy to Azure Spring Apps:

  1. 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 seconds.
    
  2. Use the following command to deploy the application code to those newly provisioned resources:

    azd deploy

    The console outputs messages similar to the ones in the following example:

    Deploying services (azd deploy)
    
    (✓) Done: Deploying service demo
    - Endpoint: https://<your-Azure-Spring-Apps-instance-name>-demo.azuremicroservices.io/
    
    
    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.com/#@/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 spring-guides/gs-spring-boot-for-azure.