Jackson JSON infinite recursion problem

Overview In this blog, we will cover a very common issue that causes the Infinity loop aka (Jackson JSON infinite recursion) when using @ManyToOne and @OneToMany relation between entities and how we can resolve them. Sample Code being used Error ERROR 26260 — [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Read more…

Use maven without Admin access on Windows OS

Overview In this blog, we will cover how to use maven without Admin access through cmd on Windows OS. Prerequisites JAVA is installed (check C:\Program Files\Java\) Apache Maven zip Download Apache Maven directly from here or choose the latest zip file from here. env.bat Create a .bat file that will help to add MAVEN and JAVA path on cmd startup. In your User’s Home dir (C:\Users\username) add env.bat file with below content Note: Don’t forget Read more…

Server Side Pagination using jQuery Datatable

Overview In this blog, we will see how to configure Server-Side Pagination in jQuery Datatable. To activate Server-Side pagination you need to pass “serverSide”: true in DataTable configuration Datatable appends a few parameters in request call whether it’s POST/GET Few of these request parameters are Similarly, Datatable also expects a few parameters in response to load table correctly. At Server-Side there will be changes to support Pagination. Here we are using Spring Web but the logic remains Read more…

RestTemplate in Spring

Overview RestTemplate reduces boilerplate code and enforces RESTful principles. In this post, we will discuss different ways in which we can use RestTemplate HTTP GET call HTTP POST call HTTP Exchange call HTTP DELETE call GET call Get entry point has two methods getForEntity: returns ResponseEntity which can be used to get ResponseStatus code and other parameters. getForObject: convert and returns Object passed to it as the parameter. In case RestTemplate is not able to parse will Read more…

Spring Retry in Action

Overview In a project, there might be a use case where you need to re-invoke a failed operation or call a method again on failure. Spring Retry provides declarative retry support for Spring applications. In this blog, we will configure and use Spring Retry logic using Spring Application. Install Dependencies Link for other versions of spring-retry. Please Note: You will also need dependent jars for Spring Retry. Example 1. Enable Spring Retry in SpringBoot Application Read more…

Session Replication in Tomcat

Overview In this blog, we will cover What is Session Replication? How to configure Session replication into multiple Server running in a Cluster. Session Replication When it comes to the high availability of Application, we generally run our server as a Cluster of multiple servers running using Load Balancer. But what if I am logged in to one of the servers and the server goes down for some reason. We do have other servers in a Read more…

Configure Load Balancing with Nginx

Overview In this post, we will cover the following points What is Nginx? Install Nginx Configuring Nginx as a load balancer What is Nginx? NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. Install Nginx Once done start serevr using below command If all goes well, in a browser hit http://localhost You should see something like this Configuring Nginx as a load balancer We are going to add Read more…

Read Dynamic Object from JSON using Gson

Overview We have seen in prev post  how to use GSON to convert a JSON to Java Object and other way around In this post, we will see how to convert JSON which has Dynamic Keys. Sample JSON If you notice in above JSON Sample_01 and Sample_20 are dynamic. In this case, we can’t simply define a Java POJO and map it to this JSON. So how do we read this kind of JSON? We will use Read more…

Bean Scope in Spring

Overview When defining a <bean> you have the option of declaring scope for that bean In this blog we will cover What are different types of Scope available in Spring.. Example for each scope type Types of Scope Scope Description singleton Scopes a single bean definition to a single object instance per Spring IoC container. prototype Scopes a single bean definition to any number of object instances. request Scopes a single bean definition to the Read more…

Dependency Injection in Spring without XML

Overview In previous blog, we saw Dependency Injection in Spring using Annotation. Here we will see how we can do the same using Annotation but without defining Autoscan in XML. We will make use of @Configuration and @Bean to define configuration the same as we did for XML in above case. Configuration Class Car Class Main Class Explanation Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC Read more…