Author: Vijay SRJ

  • How to call a REST API protected with SSL (https) from Spring Boot without importing the certificate into java keystore ?

    In the previous post we saw how to consume a REST API protected with SSL (HTTPS) by importing necessary SSL certificates into JVM keystore That serves fine if you have access to the JVM . In case if you don’t and want to bundle those certificates along with your application and use it to call…

  • How to call REST API protected with SSL (https) from Spring Boot ?

    Let’s say you want to invoke a REST API from your spring boot application. And it is protected with SSL. In other words you need an SSL certificate to access that application, else you won’t be given access to it. Your java keystore already has a lot of inbuilt certificates(In my local it is present…

  • The best way to use Optional in Java

    Null pointer exceptions. They have often been a headache to java developers. Your application breaks out of nowhere and throws null pointer exceptions. You rub your forehead then and add that null check you missed out. Java wanted to solve this problem. And they introduced the Optional keyword. They described it as a “Container” that…

  • How to create a custom annotation in Spring Boot?

    How to create a custom annotation in Spring Boot?

    Annotation is a powerful feature in Java. You can plug in some logic by just adding a word ! Consider this annotation in Spring Data: @Transactional Add this to a method where you are performing a sequence of database operations and they suddenly turn transactional. If any of the database operation fails all the other…

  • How to automate java bean to bean mapping in Spring Boot using MapStruct?

    Let’s say you are developing an application which fetches data from the database. Let’s say you are using hibernate to do the object relational data mapping. So the data you fetch from database are mapped into Java entity objects . And then you extract data from this entity object into another java bean object (DTO/data…

  • How to group related attributes together while doing hibernate entity mapping?

    Let’s say you have chosen Hibernate ORM to save data to your database. For each table you have written a corresponding entity class in your java application. And then while doing so you start noticing that a lot of the entity classes have few fields repeated. You wonder if it would be nice to keep…

  • How to automate database migration in Spring Boot using flywaydb?

    Let’s say you want to migrate your database to another environment. For example , you have your database set up in development environment and you want to migrate that to test environment. The traditional way to do that is to create scripts for each database change , store them in a file and fire them…

  • How to enable CORS (Cross Origin Resource Sharing) for specific domains in Spring Boot?

    For security reasons, browsers don’t allow javascript code to call APIs deployed in domains other than the current domain in which the javascript code is deployed. So if your javascript code is in a.com you cannot call an API deployed in b.com. So if you have deployed an API developed in Spring Boot in b.com…

  • What is a closure in Javascript?

    Let’s say you declare a variable in javascript. What is the scope of this variable? It is the entire function in which it is declared. What if it is declared within a particular block ? Still it’s scope is the entire function in which it is declared. For example: In the above code even though…

  • How do javascript functions differ from Java functions?

    How do you avoid repeated coding in a programming language? By using functions. You write the piece of code with the logic you want to execute inside a function and then call it wherever you want. Javascript functions achieve the same but differ a bit from languages like Java. Here are the features in javascript…