Posts

Showing posts from March, 2022

Dependency Inversion Types in Sprint Boot

There are two basic types of Dependency Injection:   constructor and setter.  Spring recommends constructor based dependency in most cases. From the  Spring docs : “Since you can mix constructor-based and setter-based DI, it is a good rule of thumb to use constructors for mandatory dependencies and setter methods or configuration methods for optional dependencies.” Constructor DI Let’s say I have this POJO: public class MeaningOfLife {     final int lifeInt;     final String lifeString;     public MeaningOfLife(int lifeInt, String lifeString) {         this.lifeInt = lifeInt;         this.lifeString = lifeString;     }     public int getLifeInt() {         return lifeInt;     }     public String getLifeString() {         return lifeString;     } } Here, we are using the  @Value  annotation to pick up prop...