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 Write Angular Service Unit Test

Introduction This tutorial will walk you through the process of creating a basic unit test case for an Angular service. Angular services enable you to decompose complex business logic into small, reusable units that can then be injected into components or other services using dependency injection. This tutorial is divided into two parts: One for creating a service by instantiating it sing new keyword. And another for injecting it using the Angular TestBed module....

January 31, 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

How To Use json-server To Build Mock REST API Server

Introduction A mock REST API server will often expedite your integration testing, and this tutorial will give you insight into one such server. This tutorial will walk through each step of setting up and using a fake server. Software used in this tutorial NPM : 8.3.1 Node: 16.14.0 Json-Server: 0.17.0 Setup The first step is to make sure you have node and npm installed on your workstation, then follow the next commands....

November 3, 2022

Spring Boot File Upload With RestTemplate

Introduction This quick tutorial will show you how to use Spring Boot RestTemplate to upload a file to a server. The prerequisites for this tutorial are the following the server that accepts requests for multipart file uploads A RestTemplate instance Of course, a text file to upload. What You Need This tutorial uses following softwares Java: 1.8 Spring Boot: 2.7.4 Maven: 3.6.3 How to upload a file First we create an instance of RestTemplate as...

October 19, 2022