Spring Setter vs Constructor Injection
Spring supports two types of dependency Injection, using setter method e.g. setXXX() where XXX is dependency or via constructor argument. First way of dependency injection is known as setter injection while later is known as constructor injection. Both approaches of Injecting dependency on Spring bean has there pros and cons, which we will see in this Spring framework article. Difference between Setter Injection and Constructor Injection in Spring is also a popular Spring framework interview question.Some time interviewer also ask as When do you use Setter Injection over Constructor injection in Spring or simply benefits of using setter vs constructor injection in Spring framework. Points discussed in this article not only help you to understand Setter vs Constructor Injection but also Spring's dependency Injection process. By the way if you are new in Spring framework and learning it, you may want to take a look at my list of 5 good books to learn Spring framework. That will certainly help on your learning process. Since Spring is now a must have skill for Java programmers, it worth putting time and effort to learn this powerful framework