Category: Spring Boot

  • How to share data across multiple components for a single request in a Spring Boot application?

    How to share data across multiple components for a single request in a Spring Boot application?

    Let’s say that you make a REST API request to a spring boot web application. There is a security requirement that you need to log the user id across all the method calls in the application for this particular request. Something like this: So , if your application flow starts from a controller class and…

  • Different ways to do versioning of REST APIs in Spring Boot

    Most of our web apps communicate through HTTP / REST APIs. These APIs can evolve over time. And hence maintaining different versions of them can be helpful. For example , lets say you have been hitting a REST API which returns the different products available on an ecommerce store. The owners decide to launch a…

  • Different ways to call REST APIs in Spring Boot without additional libraries

    Different ways to call REST APIs in Spring Boot without additional libraries

    In today’s world most modern web apps talk to each other through HTTP APIs. REST API is a popular standard for these HTTP APIs. So calling a REST API from your backend app is a critical functionality. Spring Boot provides multiple abstractions to do this in a simple way. Here are five different ways: Using…

  • How to query data in Spring Data through Example?

    How to query data in Spring Data through Example?

    One of the frequent operations you perform on a database is retrieving data based on certain criteria. Let’s say you have a table containing developer details , their name , experience and their primary technology skill. And you want your app to be able to query this data. There are many ways to do this.…

  • How to send emails in Spring Boot?

    How to send emails in Spring Boot?

    To send emails using the Spring Boot Email Starter in a Spring Boot application, you can do the following: STEP 1: Add the Spring Boot Email Starter dependency to your project: STEP 2: Configure the connection to the email server in your application.properties file: STEP 3 Inject the JavaMailSender bean into your service and use…

  • How to implement Event Sourcing in Spring Boot?

    How to implement Event Sourcing in Spring Boot?

    All our web applications deal with data. We store this data mostly in a database. The data which is stored thus represents the current state of the data. For example , if you have a Customer table the table will have entries which represent the current state of the customer (what their name is and…

  • How to implement Reactive Programming in Spring Boot?

    How to implement Reactive Programming in Spring Boot?

    Programming comes in different paradigms. For long , we did procedural programming using languages like C where the business logic was executed step by step in a procedural manner. Then came Object Oriented Programming where you modeled your business requirement into domain objects. It represented real world more closely and has been quite successful even…

  • How to implement Transactional Outbox design pattern in Spring Boot Microservices?

    How to implement Transactional Outbox design pattern in Spring Boot Microservices?

    Let’s say you have created a microservice. One of the APIs in the microservice does two operations: How can you make sure both are transactional? In other words if database update fails don’t send the message to the other service and if message sending fails rollback the database update? In Spring you handle transactions using…

  • How to implement event driven programming in Spring Boot?

    There are several paradigms of programming: Procedural ,Object Oriented , Functional , Event Oriented etc. Each of them comes with their own benefits and disadvantages. Most of the programming done in Java is Object Oriented since the language itself is object oriented. But what if you want to do event driven programming or at the…

  • How to implement distributed tracing using Spring Cloud Sleuth in Spring Boot?

    Microservices comes with many advantages. But there are disadvantages too. One of them is tracing the logs of your microservices. When there are so many microservices , user requests will span many of them and it will be difficult to trace the logs for a particular request when an issue occurs. To resolve this you…