Skip to main content

Posts

Showing posts from August, 2025

Deploying Spring Boot microservices on Kubernetes Cluster

This article guides you through the deployment of two Spring Boot microservices, namely "order-service" and "inventory-service," on Kubernetes using "MiniKube" . We will establish communication between them, with "order-service" making calls to an endpoint in "inventory-service." Additionally, we will configure "order-service" to be accessible from the local machine's browser . 1) Create Spring Boot microservices The Spring Boot microservices, "order-service" and "inventory-service," have been developed and can be found in this GitHub repository. If you are interested in learning more about creating Spring Boot REST microservices, please refer to this or this (Reactive) link. 2) Build Docker Images The Docker images for both "order-service" and "inventory-service" have already been generated and deployed on DockerHub, as shown below. codeburps/order-service cod...

Circuit Breaker Pattern with Resilience4J in a Spring Boot Application

Read Also: Spring Cloud Circuit Breaker + Resilience4j Resilience4j is a lightweight fault tolerance library that draws inspiration from Netflix Hystrix but is specifically crafted for functional programming. The library offers higher-order functions, known as decorators , designed to augment any functional interface, lambda expression, or method reference with features such as Circuit Breaker, Rate Limiter, Retry, or Bulkhead . These functionalities can be seamlessly integrated within a project, class, or even applied to a single method. It's possible to layer multiple decorators on any functional interface, lambda expression, or method reference, allowing for versatile and customizable fault tolerance. While numerous annotation-based implementations exist online, this article focuses solely on the reactive approach using router predicates and router functions . How Circuit Breaker Pattern works? In general, a circuit breaker functions as an automatic electrical s...

Declarative REST Client in Spring Boot (Spring 6 HTTP Interface)

Feign , an early declarative REST client, was initially part of the Spring Cloud Netflix stack and later rebranded as Spring Cloud OpenFeign . Before its introduction, crafting HTTP calls using RestTemplate involved repetitive code for each service interaction. With Feign, developers could simply define an interface with method contracts mirroring the service's endpoints. Behind the scenes, proxy magic generated a fully functional HTTP client, eliminating the need for boilerplate code . HTTP Interface (Spring Framework 6) The recent release of Spring Framework 6 integrated this declarative REST client as a native part of the core web framework in the form of the HTTP Interface . All the necessary components reside in the spring-web module, which is a transitive dependency for either the spring-boot-starter-web or spring-boot-starter-webflux modules. Currently, the WebFlux dependency is essential due to the HttpServiceProxyFactory , responsible for client gener...

Spring Reactive, Thymeleaf Hello World (Spring Webflux + Thymeleaf + JS/CSS)

In this article we will see how to create a "Spring Reactive (Webflux) project with "Thymeleaf", we will also see how to import "css", "js" and "images" and populate dynamic data. 1) Dependencies Let's create a project with , make sure to add required dependencies as shown in the picture below: Dependencies The final "pom.xml" should look something like this: 2) Static Resources We should add static resources like: "js", "css" and "images" in "src/main/resources/static" folder and "Thymeleaf(.html)" files in "src/main/resources/templates" folder as shown in the image below: Static Resources app.css index.html 3) Controller This is the place to define "requestMappings", please note how "Rendering" is used to send data from "Controller" to "Thymeleaf's" .html file. 4) Service This is just a...

AWS S3 integration with Spring Boot (AWS S3 + Spring Boot)

Updated for: Spring Boot 3 In this article we will demonstrate - how to "Download & Upload files to/from AWS S3 in a Spring Boot" project. Create a AWS S3 bucket Let's first create a AWS S3 bucket , we will use this bucket to upload/download files from a Spring Boot project. 1) Go to AWS Console and search for S3 service as shown in the picture below: 2) Now you should land on "Create Bucket" page as shown in below picture, click on "Create Bucket" button in top-right corner: 3) Provide appropriate "Bucket Name" and select "AWS Region" from the dropdown, as shown in the picture below: 4) That's it, the bucket is now created and we can use it to download/upload files: 5) In order to access this bucket from "Spring Boot" application, we need to generate "security credentials". Go to "My security credential" page by clicking on top-right dropdown and selecting ...

Reactive programming in Java with Project Reactor

Reactive programming is a declarative programming paradigm that focuses on building applications that are responsive, resilient, and scalable in the face of modern challenges like concurrency, distributed systems, and asynchronous data streams . Reactive programming provides a set of tools, patterns, and abstractions to handle asynchronous and event-driven programming more effectively. Imperative programming focuses on describing the step-by-step instructions or commands that the computer needs to follow to achieve a specific task. In this paradigm, you explicitly state how to perform each operation and control flow in your code. The emphasis is on "how" the computation should be done. int sum = 0; for (int i = 1; i Declarative programming emphasizes specifying what you want to achieve rather than detailing how to achieve it. You describe the desired outcome or the properties of the result, and the programming language or framework handles the execution detai...

How to create a basic Spring 6 project using Maven

Below is a step-by-step guide to creating a basic Spring project using Maven. 1) Create a Maven Project Use the following Maven command to create a new Maven project. mvn archetype:generate -DgroupId=com.tb -DartifactId=spring-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 2) Import in IntelliJ IDEA If you haven't already, open IntelliJ IDEA on your system. Go to "File" > "New" > "Project from Existing Sources..." . In the file dialog, navigate to the directory where your Maven project is located. Select the pom.xml file within the project directory and click "Open." 3) Update pom.xml In total, the application requires the below-mentioned dependencies: 4) Create Spring Configuration Create a Java configuration class that uses annotations to define your Spring beans and their dependencies. This class should be annotated with @Configuration . 5) Create the Main Application C...

Memory footprint of the JVM (Heap & Non-Heap Memory)

JVM consumes the available space on host OS memory. However, inside the JVM, there are separate memory spaces to store different types of data and code. The JVM divides its memory into two main categories: heap memory and non-heap memory . 1) Heap Memory The Java Heap is the area where all java class instances and arrays are allocated at runtime. It is managed by the JVM's garbage collector , which automatically handles memory allocation and deallocation for objects that are no longer in use. The size of the Java Heap can be configured using JVM command-line options, such as -Xmx (maximum heap size) and -Xms (initial heap size) . As the application runs, the JVM may dynamically adjust the size of the heap based on the application's memory requirements and the garbage collector's behavior. The Java Heap is further divided into regions, such as the Young Generation, Old Generation , and possibly other special regions like Eden space and Survivor spaces . Th...

Spring Boot Login/Logout (Spring Security + MySql + Thymeleaf)

Updated for: Spring Boot 3 This article is going to discuss how to implement "login/logout" and "authentication/authorization" in a "Spring Boot 3" application. To demonstrate the functionality, a new "Spring Boot" application is created with the help of spring initializr . In order to save/get user details (name, email or username, roles) the application is using the "MySql" database. The application also uses thymeleaf as a server-side template engine. The idea is to create a custom "registration" and "login" flow based on "thymeleaf (html)" forms. Prerequisite This application requires an existing database in MySql; this can be achieved with the help of the below-mentioned query: CREATE SCHEMA `spring-security-form-login` ; Dependencies pom.xml The "spring-boot-starter-security" combines Spring Security dependencies, and the "spring-boot-starter-web" enabl...