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

Create Maven Project Through Command Line

Introduction How often do you create a Maven project from your preferred editor? The response would be frequently or always. But have you ever thought about what Maven command your editor used to create the project? Yes, maven projects are built solely with the maven command, exactly as “mvn clean install” is used to create a project’s jar file. This tutorial will teach you about such a command. Maven Command Open your terminal and navigate to the directory in which you want to create a new Maven project....

November 29, 2022

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
Log4j How to Log Message to Console

Log4j How to Log Message to Console

Introduction This tutorial will help you to log all level messages into console using Log4j plugin. In previous tutorial we have seen how to setup the log4j plugin in Maven and simple logging application. If you need to understand the basic of Log4J the visit previous tutorial. What we will do in this tutorial We saw in the previous tutorial that Log4J’s default configuration set the logging level to Error, causing it to log only errors and fatal messages to the console....

June 1, 2022
Getting Started With Log4j

Getting Started With Log4j

Introduction For Java applications, Log4j is a commonly used and trusted logging tool. When an application is deployed to an application server, logging is a must-have feature. In this tutorial, we’ll see how to set up Log4j for a simple Java application. You can find all code related to this tutorial inside GitHub project. Why do we need Logging Logging is an important part of the application since it records user actions, input requests and output responses, error messages, and more....

May 30, 2022
Maven Create Jacoco Code Coverage Report

Maven Create Jacoco Code Coverage Report

Introduction In this tutorial we will see how to setup the JaCoCo plugin to generate a code coverage report for a Maven project. In order to generate a unit test coverage report, we should have sufficient unit test cases in our application. For this tutorial, I am referring to a Maven project which has a string manipulation method. You can find this project at this GitHub location. There are a few steps that need to be taken to produce the report....

May 26, 2022