Java Application in Azure Spring Apps

Tharushi nimasha dewangi
8 min readOct 17, 2023

--

Azure Spring Apps makes infrastructure of Spring Apps applications so developers can focus on their code.

Use Spring Cloud to develop Java apps and publish to Azure

  • Examine the application components based on the information provided in its GitHub repository.
  • Consider the Azure services most suitable for hosting your application.
  • Consider the Azure services most suitable for storing data of your application.
  • Consider resource organization in Azure.
  • Consider tools for connecting to and managing your Azure environment.

Functional services

  • Customers service: Contains general user input logic and validation including pets and owners information (Name, Address, City, Telephone).
  • Visits service: Stores and shows visits information for each pet in comments.
  • Vets service: Stores and shows Veterinarians’ information, including names and specialties.
  • API Gateway: The API Gateway is a single entry point into the system, used to handle requests and route them to an appropriate service or to invoke multiple services, and aggregate the results

The three core services expose an external API to client. In real-world systems, the number of functions can grow quickly with system complexity. Hundreds of services might be involved in rendering one complex webpage.

Azure Spring Apps provides tools that enhance Spring Boot applications to implement the following patterns:

  • Config service: Azure Spring Apps Config is a horizontally scalable centralized configuration service for distributed systems. It uses a pluggable repository that currently supports local storage, Git, and Subversion.
  • Service discovery: It allows automatic detection of network locations for service instances, which could have dynamically assigned addresses because of autoscaling, failures, and upgrades.

Refer — https://github.com/Azure-Samples/spring-petclinic-microservices/tree/labstarter

Use Azure services for storing application data

Azure platform offers several database-as-a-services options, including Azure SQL, Azure Database for MySQL, and Azure Database for PostgreSQL.Your choice of the database technology should be based on the following requirements for the Spring Petclinic application:

  • The target database service should simplify the migration path from the on-premises MySQL deployment.
  • The target database service must support automatic backups.
  • The target database service needs to support automatic patching.

Organize the Azure resources

Now that you have an understanding of which Azure services, you can start working through the first initial stages of migrating the Spring Petclinic application. You’ll need to plan how the resource will be organized in Azure prior to creating the resources. To address this need, try to answer the following questions:

  • How many resource groups will you be creating for hosting your Azure resources?

It’s a good practice for all Azure resources that are created together for a purpose to be associated with the same resource group. For this exercise that includes one application, you could deploy all resources for this application into a single resource group.

  • How will you configure networking for the application components?

You could deploy Azure Spring Apps either into a virtual network or without a virtual network dependency. The latter approach will simplify the task of making the initial migration of the application accessible from the Internet. In a subsequent exercise, you’ll modify your approach to accommodate extra requirements. For now, you won’t create a virtual network for Azure Spring Apps.

Note

For Azure Kubernetes Service, you would need at least one subnet in a virtual network to run Azure Kubernetes Service cluster nodes. The subnet can be small (for example, /26), thus allowing for a total of 64 IP addresses.

The Azure Database for MySQL deployment won’t require virtual network connectivity for the first phase of the migration of the application. Modified in a subsequent exercise for implementing security measures for protection of the full application stack.

  • Are there any supporting services you would need for running the application?

For running Azure Spring Apps, no extra supporting services are needed during the first phase of the migration. All you need is the compute platform and a database.

For running Azure Kubernetes Service, you’ll need a container registry for storing container images to be deployed to the cluster. You can use Azure Container Registry.

Choose the right tools

  • What tools do I need for connecting to the Azure?

You can connect to the Azure using the Azure portal or command line tools such as Azure CLI. Using Azure CLI might be more challenging, but it allows for scripting setup tasks and common tasks repeatable.

Important

Make sure you can log into the Azure portal by using the credentials that were provided to you.

You should record most commands and scripts you execute for later reference. Making note of the commands will help you in the subsequent exercises for reuse of similar commands.

What other tools would you need to perform the migration?

  • If you’re using Azure Spring Apps as the target platform, there are no more tools required for the migration steps.
  • If you’re using Azure Kubernetes Service as the target platform, you’ll need Docker tools to containerize the microservices for the application. You’ll also need to consider the optimal base image for containerizing the microservices.

Azure services for hosting Java applications on Azure Spring Apps

Now that you’re familiar with the sample application that you’ll be migrating to Azure, you need to review the various compute options for hosting the application.

The three primary options to consider are Azure App Service, Azure Kubernetes Service, and Azure Spring Apps.

Azure App Service

Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on both Windows and Linux-based environments.

App Service not only adds the benefits of Microsoft Azure to your application, such as security, load balancing, autoscaling, and automated management. DevOps capabilities, such as continuous deployment from Azure DevOps, GitHub, Docker Hub can package management, staging environments, custom domain, and TLS/SSL certificates.

Azure App Service is a fully managed platform as a service (PaaS) offering for developers. Here are some key features of App Service:

  • Multiple languages and frameworks — App Service has first-class support for ASP.NET, ASP.NET Core, Java, Ruby, Node.js, PHP, or Python. You can also run PowerShell and other scripts or executables as background services.
  • Managed production environment — App Service automatically patches and maintains the OS and language frameworks for you.
  • Containerization and Docker — Contain your app and host a custom Windows or Linux container in App Service. Run multi-container apps with Docker Compose. Migrate your Docker skills directly to App Service.
  • Global scale with high availability — Scale up or out manually or automatically. Host your apps anywhere at Microsoft’s global datacenter infrastructure, and the App Service SLA provides high availability.
  • Visual Studio and Visual Studio Code integration — Dedicated tools in Visual Studio and Visual Studio Code streamline the work of creating, deploying, and debugging.

Azure Kubernetes Service

Azure Kubernetes Service simplifies deploying a managed Kubernetes cluster in Azure by offloading the operational overhead to Azure. As a hosted Kubernetes service, Azure handles critical tasks, like health monitoring and maintenance. Since Kubernetes masters are managed by Azure, you only manage and maintain the agent nodes. Thus, AKS is free; you only pay for the agent nodes within your clusters, not for the masters.

You can create an Azure Kubernetes Service cluster using:

When you deploy an Azure Kubernetes Service cluster, the Kubernetes master and all nodes are deployed and configured for you. Advanced networking, Azure Active Directory integration, monitoring, and other features can be configured during the deployment process.

Azure Spring Apps

As part of the Azure ecosystem, Azure Spring Apps allows easy binding to other Azure services including storage, databases, and monitoring.

  • Azure Spring Apps is a fully managed service for Spring Boot apps that lets you focus on building and running apps without managing infrastructure.
  • Deploy your JARs or code for your Spring Boot app or Zip for your Steeltoe app, and Azure Spring Apps will automatically wire your apps with Spring service runtime and built-in app lifecycle.
  • After deployment you can monitor app performance, fix errors, and rapidly improve applications.
  • Full integration to Azure’s ecosystems and services.
  • Azure Spring Apps is enterprise ready with fully managed infrastructure, built-in lifecycle management, and ease of monitoring.

Because the Spring Petclinic application consists of multiple interactive microservices, what would you consider to be the most suitable option? Before you answer this question, review the following requirements:

  • The Spring Petclinic application should be accessible via a public endpoint to any user (anonymously).
  • The new implementation of Spring Petclinic should eliminate the need to manually upgrade and manage the underlying infrastructure. Instead, the application should use the platform-as-a-service (PaaS) model.
  • Spring Petclinic implementation adheres to the principles of the microservices architecture. Each component of the application runs as a microservice and granular control over cross-component communication. The application will evolve into a solution that will provide automatic and independent scaling of each component and extend to include more microservices.

You’ll need to consider other steps to migrate the labstarter branch of the GitHub repo hosting the Spring Petclinic application code to the target service.

Use the table to organize your thoughts around what is appropriate for using Azure App Service, Azure Kubernetes Service, and Azure Spring Apps:

Considerations for choosing a service

Suggestions for reviewing which are the most appropriate service to be deployed for the Spring Petclinic application.

  • Azure App Service, Azure Kubernetes Service, and Azure Spring Apps each support a public endpoint that can be accessed anonymously.
  • Azure App Service, Azure Kubernetes Service, and Azure Spring Apps each support automatic upgrades and eliminates the need to manage the underlying infrastructure.
  • With Azure App Service, upgrades are automatic. All underlying infrastructure is managed by the platform.
  • Using Azure Kubernetes Service, you can enable automatic upgrades based on the channel of your choice (patch, stable, rapid, node-image). The underlying infrastructure consists of virtual machines that you provide as part of agent pools, however you don’t manage them directly.
  • With Azure Spring Apps, all tasks related to upgrading and managing the underlying infrastructure are taken care of by the platform. While Azure Spring Apps is built on top of an Azure Kubernetes Service cluster, that cluster is fully managed.
  • Both Azure Kubernetes Service and Azure Spring Apps offer a convenient approach to implementing the microservices architecture. Additionally, they provide support for Spring Boot applications.
  • If you choose Azure App Service, you’ll need to create a new web app instance for each microservice. Both Azure Kubernetes Service and Azure Spring Apps require only a single instance. Additionally, Azure Kubernetes Service facilitates controlling traffic flow between microservices by using network policies.
  • Azure Spring Apps Service offers an easy migration path for existing spring boot applications, which is an advantage for your existing application.
  • Azure Spring Apps Service eliminates any administrative overhead required to run a Kubernetes cluster, which simplifies the operational model.
  • Azure Kubernetes Service requires an extra migration step that involves containerizing all components.
  • You’ll also need to implement Azure Container Registry to store and deploy your container images from.
  • Running and operating an Azure Kubernetes Service cluster introduces more involvement.
  • Azure App Service scalability is more limited than Azure Kubernetes Service or Azure Spring Apps Service.

Conclusion

Given all the constraints and features, the most beneficial services for supporting the Spring Petclinic application are Azure Spring Apps or Azure Kubernetes Service.

For this exercise, you’ll be using Azure Spring Apps as the service to be deployed for the Spring Petclinic application. In this learning path, you’ll be using a subset of resources from the PetClinic sample application located on the lab starter branch of the GitHub repo hosting the Spring Petclinic application code repository.

--

--