Posts

Showing posts from September, 2022
  Spring Boot  Injection How do you want spring to inject the beans?  This can be done in 3 ways Constructor Setter Field There are so many forums discussing about which one to follow. I am not going to the debate on this topic but you should understand the core principle of each usage and use based on that. What is the core principle?  First, Let's discuss about the Field injection -> Do you think how spring injects the bean even-though you specify the field as private access?  hmm.. ya, I got this based on Reflection..  isn't it violates encapsulation? Yes, it does. So, we as a developer avoid using Field injection. is there any places that can be used? Yes, We can use it in test classes.  So, we are some understanding about Field injection. Now, move on to Setter injection. Snippet code private EmployeeRepository employeeRepository; public void setEmployeeRepository(EmployeeRepository employeeRepository) {     this.  employeeReposi...