Create OpenAPI Specification In Existing SpringBoot Project

Introduction The OpenAPI specification is used to design the REST API structure, it is an agreement that clients use to call those REST API services. As per industry standard, we design the OpenAPI specification first, then utilise it in applications to generate REST API services. This phase is not helpful for ongoing projects if a REST API has already been developed because it is a new practise. We need a clever solution to automatically build OpenAPI specifications for these kinds of projects so that their clients can utilise the specifications to create client applications or conduct testing....

June 19, 2023

How To Use @ConfigurationProperties In Spring Boot

Introduction This tutorial will show you how to use @ConfigurationProperties in a Spring Boot application. This annotation is designed to load properties from an application property file into an application context and configure them using a Java object. Why do we need @ConfigurationProperties? What about the @Value annotation? The typical method of registering configuration properties to a Java object field in a Spring Boot application is the @Value annotation, but it is only acceptable for single independent configuration....

February 9, 2023

How To Make Spring Boot Controller Unit Test Faster

Introduction There are several methods for testing Rest controllers in the Spring Boot framework, and this post will demonstrate one of the quickest. Tools Spring Boot: 2.7.6 Java : 11 Rest Controller Let’s create a simple REST API controller with one service to fetch the data from the database. UserController.java @RestController public class UserController { private final UserService userService; public UserController(final UserService userService) { this.userService = userService; } @PostMapping(path = "/user", consumes = MediaType....

January 10, 2023

Easy Steps To Create Log4j2 Rolling File For Spring Boot

Introduction Spring Boot applications can save informative messages or application errors to a file. This functionality allows you to monitor the application’s health and take necessary action when problems arise. Logging all of this information to a single file, on the other hand, will cause the file to expand in size, which would be a nightmare if the file size rose to MB or GB and you wanted to trace a specific exception throughout the whole log file....

November 20, 2022

Two Steps To Add Log4j2 To Spring Boot Application

Introduction Log4j2 is a comprehensive and modern framework for logging messages in applications. And Spring Boot, which is widely used in industry, provides excellent support for Log4j2. In this tutorial, we will look at how to configure it using an XML and YAML file. Setup Download the Spring Boot application from Spring Boot Starter and extract the zip file. POM Configuration Add log4j2 as a dependency to the pom.xml file. pom....

November 17, 2022

First Step Toward Spring Boot Cloud Gateway

Introduction This tutorial is a short introduction to Spring Cloud Gateway. By following the quick and easy steps provided below, you will be able to start the REST API gateway project. Prerequisite Java Maven Spring Boot Download the Spring Boot project from Spring Initializr and select Gateway as dependency. Now generate and download the project and use your favourite editor to import it. Gateway Configuration You can use a YAML file or Java code to configure routes....

November 7, 2022
Spring Boot Resttemplate Guide With Example

Spring Boot Resttemplate Guide With Example

What is RestTemplet? RestTemplate is a HTTP Client library that provides basic APIs for executing different HTTP type requests. RestTemplate is one of the HTTP libraries available on the market. The Spring Boot team designed and maintains it. As previously said, it is a client library, which means it may be utilised in our application as a stand-alone dependency. To utilise it, you don’t require a complete Spring boot application....

April 22, 2022
How to Enable Sql Logs in Spring Boot Application

How to Enable Sql Logs in Spring Boot Application

Introduction This tutorial will demonstrate how to enable and disable SQL log statements in a Spring Boot application in order to debug SQL flow. Problem You will frequently need to debug the SQL statement while developing a Spring Boot application with a SQL database. SQL debug logs can assist you figure out what’s wrong with JPA statements and whether or not there’s a problem with database connectivity. Example If you’ve built custom Spring data JPA methods and need to know what SQL statement is being utilized behind them,...

April 8, 2022