What are the differences between constructor injection and setter injection?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Feb 22, 2018

 

The difference between Constructor Injection and Setter Injection are:
  • In constructor injection, there’s no partial injection while setter injection provides for partial injection.
  • Constructor injection overrides the setter property while setter injection overrides the constructor property.
  • Constructor injection creates a new instance for any kind of modification while setter injection doesn’t.
  • Constructor injection works better for many properties while setter injection works better for few properties.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Spring interview questions

    What are the features/ characteristics of spring?

    The important features of spring are as follows:Lightweight: Considering transparency and size, spring is lightweight..

    Spring interview questions

    How many types of modules are there in spring? Name them.

    There are around twenty modules, which can be categorized into Core Container, Web, Data Access or Integration, Aspect ..

    Spring interview questions

    What do you mean by Spring Java Based Configuration?

    Spring configuration files are XML files. These files contain the information of classes and describe how these classes..