Build and deploy full-stack Java Web Applications on Azure Container Apps with JHipster
As full-stack Java developers look to modernize their applications for the cloud, finding a platform that offers scalability, flexibility, and strong support for the Java ecosystem is essential. Azure Container Apps provides an ideal environment for running Java applications, offering built-in Java Support features like automatic JVM memory fit, managed Spring Components, and integrated JVM monitoring. By pairing this with JHipster, a powerful tool to generate and deploy Spring Boot applications, you can easily build, deploy, and scale your full-stack web applications on Azure.
In this blog post, we’ll walk through how to use JHipster to deploy full-stack web applications on Azure Container Apps, featuring a React front-end, a Spring Boot back-end, and various database options such as PostgreSQL and MongoDB. Additionally, we will guide you on how to enable the Java stack feature after deployment to take advantage of enhanced Java support.
What is JHipster?
JHipster is an open-source development platform designed to generate, develop, and deploy modern web applications and microservices architecture. It stands for “Java Hipster” and provides a scaffolding for full-stack applications using popular frameworks and technologies. As one of the most successful application generators, JHipster helps developers rapidly create production-ready, secure applications by combining best practices in modern Java development with front-end frameworks.
Why Java on Azure Container Apps?
Java remains a dominant programming language for building enterprise-grade applications, and Azure Container Apps has built-in supports for the Java ecosystem comprehensively. Here’s why Azure Container Apps is a great fit for Java applications:
Seamless Java Integration: Azure Container Apps natively supports Spring Boot and other popular Java frameworks, ensuring easy deployment and performance tuning of Java applications.
Integrated JVM Monitoring and Diagnostics: Leverage Azure Monitor with Java Virtual Machine (JVM) metrics to gain deep insights into the performance of your Java applications and troubleshoot issues with ease.
Managed Service: Azure Container Apps offers Java components as managed service such as Service Registry (Eureka Server), Config Server, and Spring Boot Admin, which provide service discovery, centralized configuration management, and monitoring for Spring Boot applications, simplifying microservices management and improving application observability.
Dynamic Scaling: Automatically scale your Java services based on HTTP requests, events, or custom metrics without managing the underlying infrastructure.
With Azure Container Apps, Java developers can build cloud-native applications and deploy them effortlessly, taking advantage of the best practices baked into the platform.
Step-by-Step Guide: Deploying Java Applications on Azure with JHipster Azure Container Apps
In this section, we will walk you through the process of deploying a full-stack ToDo application on Azure with JHipster Azure Container Apps. This guide covers prerequisites, installing the generator, building the project, and deploying it to Azure.
Prerequisites
The following prerequisites are required to run the JHipster application locally. Please ensure that these tools are installed and configured on your local machine:
Java 17 or later: Required for running the Spring Boot API backend.
Download and install Java if you haven’t already.
Node.js: Essential for building and running the web frontend (React).
Install from Node.js official website.
Maven (Optional): Used to build the Java backend locally, you can choose your own build tools.
Install Maven by following instructions from the Apache Maven website.
The following prerequisites are required to deploy the application to Azure. Make sure you have access to these tools for the deployment process:
Azure Subscription: You need an active Azure subscription to deploy to Azure Container Apps. You can start with the monthly free grants, which includes 180,000 vCPU seconds, 360,000 GiB/s, and 2 million requests each month.
Try Azure Container Apps for free.
Docker: Docker is used by JHipster to containerize your application and push the images to Azure.
Download Docker if you don’t have it installed.
Azure Developer CLI: This tool helps manage the Azure resources for your project and makes deploying the application to Azure Container Apps simpler.
Install the Azure Developer CLI.
Step 1: Install JHipster Azure Container Apps Generator
First, you need to install the JHipster Azure Container Apps generator globally. This tool simplifies deploying JHipster applications to Azure Container Apps.
npm install -g generator-jhipster-azure-container-apps
Step 2: Run the Generator
To generate your JHipster application with Azure Container Apps support, use the following command:
jhipster-azure-container-apps
Step 3: Run the Application Locally
You can easily run your JHipster application locally to test it before deploying it to Azure.
For the back-end:
1. Navigate to the src/api directory and manually build the back-end:
Here I used Maven, but you can choose your own package installation utility:
mvn clean package -DskipTests
2. Run the back-end Java service:
java -jar target/{artifactname}-0.0.1-SNAPSHOT.jar
3. Access the back-end API locally at:
http://localhost:3100/
For the front-end:
1.Navigate to the src/web directory and build the front-end:
npm install
2.Start the development server:
npm run dev
3.Access the front-end locally at:
http://localhost:3000/
Step 4: Deploy to Azure for Free
Once you’re ready to deploy your application, you can use the Azure Developer CLI (azd) to set up the Azure resources and deploy your project. Azure Container Apps offers monthly free grants, which includes 180,000 vCPU seconds, 360,000 GiB/s, and 2 million requests per month.
1. Log in to Azure Developer CLI. This only needs to be done once after installation:
azd auth login
Note: If you’re on Windows, ensure you have PowerShell installed.
2.Navigate to the project directory and deploy to Azure with the following command:
azd up
Make sure your docker is running when executing this.
This command will provision the necessary Azure resources and deploy your application.
3. Once the deployment is successful, you will see the following output:
SUCCESS: Your up workflow to provision and deploy to Azure completed in <deployment-time>.
The output Deploying service api and Deploying service web are the endpoints to access the todo application.
Manage your applications on Azure Container Apps with built-in Java Support
Now that your application is up and running, you can fully leverage the scalability and flexibility of Azure Container Apps for your Java projects.
Azure Container Apps provides built-in Java support to enhance your applications with features like automatic memory fit, diagnostics, and managed Spring components. To enable these features, simply navigate to the “Manage” section of the Development Stack on your application’s overview page and select “Java.” This allows you to unlock advanced Java support, improving performance and monitoring capabilities for your cloud-native Java applications.
You can learn more Java experiences on Azure Container Apps at Announcing the General Availability of Java experiences on Azure Container Apps.
Microsoft Tech Community – Latest Blogs –Read More