Skip to main content

Posts

Getting Started With Log4j Logging

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. This information aids in the understanding of the application both inside and outside of it, as well as providing faster feedback or support for any issues that may occur during the application's execution. Maven configuration Add following dependencies into pom.xml pom.xml <dependencies> <dependency> <groupId> org.apache.logging.log4j </groupId> <artifactId> log4j-api </artifactId> <version> 2.17.2 </version>

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. Install the Maven JaCoCo plugin. Insert the following code into pom.xml. <plugin> <groupId> org.jacoco </groupId> <artifactId> jacoco-maven-plugin </artifactId> <version> 0.8.2 </version> <executions> <execution> <goals> <goal> prepare-agent </goal> </goals> </execution> <execution> <id> report </id> <phase> test <

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. It's suitable for use in simple Java applications as well as other frameworks such as Micronaut, Play and others. Setup Add RestTemplate dependency to project, for this tutorial I am creating a simple java application to consume HTTP request and a node application to provide HTTP service. For Gradle build tool Add the following dependency in the build.gradle file . // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web implementation group: 'org.springframework.boot' , name: 'spring-boot-starter-w

How to Change a Git Commit Message?

In this tutorial, we'll go over how to fix Git commit messages that have been committed to a local or remote Git repository. Reason to change commit message? When working with Git, there could be several reasons to update the commit message. Some of the common reasons are as follows: Message contains a typo. Missing intent of commit. Remove any confidential information. Correct issue ticket number to connect to an issue tracker such as Jira. Solution The reason could be anything, but you should be aware of the command to update the commit message at any point in the development of your application. Let's take a look at the solution for a single commit message. local commit Assume you perform the following Git operation $ git add -A $ git commit -m "[PROJECT-99] - Added user profile module." And after you realise that the issue number for the current commit is incorrect and needs to be corrected. That's the story of Project 100. You can correct it

How to enable SQL logs in Spring Boot application?

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, return repository . findByUsernameIn ( usernames ); Then you can enable Hibernet debug mode to log SQL statements. Solution Update the application.yml file with the Hibernet configuration as logging: level: org: hibernate: DEBUG or application.properties as logging.level.org.hibernate=DEBUG The SQL statement will appear in the application logs after modifying the configuration file and restarting the application. 2022-04-07 08:41

Cucumber setup using Gradle

This tutorial will help you configure Cucumber into a Java project using the Gradle build tool. Introduction Cucumber is a test automation tool that supports Behavior-Driven Development (BDD).  It is written in plain English text called "Gherkin." Cucumber enables you to write test cases that anyone can easily understand, regardless of their technical knowledge. Setup First, create a Gradle project using the gradle init command. > gradle init Complete the Gradle wizard to create a project. Now update the gradle.build file to add the Gradle Cucumber dependency. testImplementation 'io.cucumber:cucumber-java8:7.0.0' This will add Cucumber implementation to your project. Task Configuration Add the following configuration to gradle.build This will enable the Cucumber runtime to execute BDD test cases. configurations { cucumberRuntime { extendsFrom testImplementation } } Create a new custom task to execute Cucumber  task cucumber ()

Getting started with Micronaut using Gradle

Getting started In this tutorial, we will create a Micronaut application using Gradle. Github Link What you will need Java installed on your machine Gradle installed on your machine Text Editor Steps First create your project folder, we will make a folder called "micronaut-project" for this tutorial. The second step is to add the build.gradle  file inside the project folder. This will contain a script to build the Micronaut application. Now update the build.gradle file. 1. Add following plugin plugins { id( "com.github.johnrengelman.shadow" ) version "7.1.1" id( "io.micronaut.application" ) version "3.2.0" } This will help to build application executable jars.        2. Next, add dependencies. dependencies { annotationProcessor( "io.micronaut:micronaut-http-validation" ) implementation( "io.micronaut:micronaut-http-client" ) implementation( "io.micronaut:micronaut-jackson-databind" )

Subscribe for latest tutorial updates

* indicates required