Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference Between Constructor and Setter Injection

 
jinesh parikh
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was reading this post on why people use setter injection more than constructor injection.But I could not understand the first reason as well.

Spring maintained its focus on setter injection because at the time, we believed that the lack of default arguments and argument names for constructor arguments resulted in less clarity for developers


can somebody please explain me the first reason stated above?

Any help would be appreciated.

Regards,
Jinesh
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference you quoted is simply stating that constructor args do not have names in the spring configuration XML, which can make it less clear for developers. That said the thread you were looking at is quite old and the new and more preferred approach today is Spring's annotation based field injection using @Autowired, @Inject, and @Resource. In this case setters are not required.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic