Category: Uncategorized

  • How to create an accordion in HTML5?

    Creating an accordion got easier in HTML5. You don’t need to use div element and javascript anymore. You just need to use the <details> element. The label in the accordion can be represented using <summary> element nested inside the <details> element and the data inside the accordion can then be represented using <p> (paragraph) element…

  • How to read HTTPRequest in Spring Boot Exception Handler?

    Let’s say you want to centralize exception handling in your spring boot application. Whenever any of your APIs throw exception you want to handle them in a centralized way. How can you do this? Using Spring’s Exception Handler. You create a class annotated with @ControllerAdvice annotation and write a method annotated with @ExceptionHandler . You…

  • Day 100 – Wrapping It Up

    Feeling a sense of relief, today is the 100th day of another 100 day project : Post one technical post per day for 100 days. On the third day after lockdown was announced in Tamilnadu, I started working on this idea. This has kept my mind occupied. I have stopped following news about corona spread…

  • On Maven Wrapper

    Let’s say you have built a project using maven. You used a specific version of maven to build it. Now you want to send this project to your friend. To build your project , your friend first needs to install maven in his machine. And also he might need to use the specific version you…

  • How to use Spring WebClient to invoke REST services reactively and non reactively?

    Let’s say you want to invoke a reactive REST service developed using Spring WebFlux. A reactive REST service is one which lets you invoke itself asynchronously. You either get a Mono response (for a single object response) or a Flux response (for multiple objects). Here is a demo of how to call a reactive REST…

  • How to run environment specific code in Spring Boot?

    Let’s say you want to run environment specific code in your Spring Boot application. Say if the environment is local , you get data from a temporary cache and if the environment is anything higher you get it from a third party service. How to do this? You can specify the environment to be activated…

  • How to write recursive queries in SQL?

    Let’s say you want to find out all the subordinates to a manager recursively. That is say Kiran reports to Guru and Gayathri reports to Kiran , then the subordinates of Guru are both Kiran and Gayathri. This can be done using recursive queries. Let’s see how to do it in PostgreSQL. This is supported…

  • How to do user authentication in Spring Boot using PostgreSQL database?

    Let’s say you want to create an application in Spring Boot and authenticate the users who use it against credentials stored in a PostgreSQL database. Below are the high level steps to implement it in Spring Boot: Create a spring boot project with authentication related dependencies. Add the database configuration in application.properties against which you…

  • How to auto generate and auto increment identifier values for PostGreSQL tables through Hibernate?

    I was trying to connect to PostGreSQL database through Spring Boot. I used spring-boot-starter-data-jpa dependency which automatically included hibernate dependencies to the project. And since I was connecting to postgresql database I included the following postgresql dependency as well: I created a simple table named my_table with an integer ID and a JSON data type…

  • How to preserve newline character in YAML property value?

    I dealt with a particular use case in my project. I had to fetch a string with newline characters from a yaml property file. The string value was something like this: quote: “I am Bond \n James Bond” The problem was when I fetched this quote property in my code , it got modified into…