IFI Techsolutions

Spring Boot Application deployment to Azure Spring Cloud

Authors- Rajat Malik (Cloud Engineer), Anubhav Bisht (Associate Cloud Engineer)   Overview This walkthrough explains how to deploy a simple Azure Spring Cloud microservice application to run on Azure. If you want to know more about Azure Spring Cloud, you can read here: https://ifi-prod-poc-2.azurewebsites.net/2020/09/15/introduction-to-azure-spring-cloud/ The application code used in this tutorial is a simple app […]

Authors- Rajat Malik (Cloud Engineer), Anubhav Bisht (Associate Cloud Engineer)

 

Overview

This walkthrough explains how to deploy a simple Azure Spring Cloud microservice application to run on Azure. If you want to know more about Azure Spring Cloud, you can read here: https://ifi-prod-poc-2.azurewebsites.net/2020/09/15/introduction-to-azure-spring-cloud/

The application code used in this tutorial is a simple app built with Spring Initializr. When you’ve completed this example, the application will be accessible online and can be managed via the Azure portal.

This quickstart explains how to:

  • Generate a basic Spring Cloud project
  • Provision a service instance
  • Build and deploy the app with a public endpoint

 

Prerequisites

Before we start with the quickstart, we will need the following:

 

Generate a Spring Cloud project

Start with Spring Initializr to generate a sample project with recommended dependencies for Azure Spring Cloud. The following image shows the Initializr set up for this sample project.

Click to open the Spring Initializr

Azure Spring Cloud App-1

Once the Artifact name and other dependencies are set, Click Generate. Download the zip file and and extract the package to a folder.

The next step is to create a HelloController.java file (web controller for a simple web application) by adding a new file in the src/main/java/com/example/helloIFI/ folder as follows (same can be done using a code editor):

Azure Spring Cloud App-2

Set up an instance of Azure Spring Cloud

The following procedure creates an instance of Azure Spring Cloud using the Azure portal. For this, open your browser and follow the following steps:

  • In a new tab, open the Azure portal.
  • On the top left of the portal, click on the hamburger button(), click on  Create a resource, search for Azure Spring Cloud.
  • Select Azure Spring Cloud from the results as shown in the image:

Azure Spring Cloud App-3

 

Azure-Spring-Cloud-App-

Fill out the form on the Azure Spring Cloud Create page. Consider the following guidelines:

  • Subscription: Select the subscription you want to be billed for this resource.
  • Resource group: Creating new resource groups for new resources is a best practice. This will be used in later steps as <resource group name>.
  • Service Details/Name: Specify the <service instance name>. 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.
  • Location: Select the region for your service instance.

Azure-Spring-Cloud-App-5

Make sure that you use globally unique name while spinning up the Azure spring cloud.

Once you fill the Subscription, Resource Group, unique name, Region and select the Pricing Tier, click on Review & create.

 

Build and Deploy Process

  1. On your local machine, open a command prompt by typing cmd on the address bar of the folder where you have extracted the helloIFI folder (downloaded and extracted from Spring Initializr above). We are going to build this project using Maven by typing the following command in the command prompt
    [dt_code]mvn clean package -DskipTests [/dt_code]

Azure-Spring-Cloud-App-6

Once the build is complete, a HelloIFI-0.0.1-SNAPSHOT.Jar file is created in the \target folder, which you can check by going to the C:/Users/<username>/HelloIFI/target folder.

Azure-Spring-Cloud-App-7

 

2. You can install the Azure Spring Cloud extension for the Azure CLI (You might need to use azlogin if you are logging in from Azure CLI for the first time, to connect to your Azure account) by running the following command on the command prompt:

[dt_code]az extension add –name spring-cloud[/dt_code]

3. To create the app with public endpoint assigned, run the following command:

[dt_code]az spring-cloud app create -n helloIFI -s <service instance name> -g <resource group name> –is-public[/dt_code]

Azure Spring Cloud App-8

 

Azure Spring Cloud App-9

 

4. The next step is to deploy the Jar file for the app using the following command:

[dt_code]az spring-cloud app deploy -n helloIFI -s <service instance name> -g <resource group name> –jar-path target\helloIFI-0.0.1-SNAPSHOT.jar[/dt_code]

Azure Spring Cloud App-10

 

5. It takes a few minutes to finish deploying the application. To confirm that it has deployed, go to the Apps blade in the Azure portal. You should see the status of the application. 

Azure Spring Cloud App-11

 

Click on the Test Endpoint link to get the actual output of the application in the web.

Azure Spring Cloud App-12

 

So, this walk through showed how you can deploy a Spring based application to Azure Spring Cloud for hosting and monitoring purpose. There are many other features like Networking, Scaling, etc. Depending upon the requirement of the project and the application you can configure them accordingly.

Leave a Reply

Subscribe to our knowledge library.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare