This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes using setter method in spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "using setter method in spring" Watch "using setter method in spring" New topic

using setter method in spring

adarsh datt

Joined: Aug 28, 2006
Posts: 8
Why do we have to write a setter method inside a controller class when we declare an object variable instead of directly creating an object?
Hussam Bamatraf

Joined: Aug 25, 2003
Posts: 14
This allows the Spring container to inject the required object by reading the proper class name from beans configuration file.
This is called "Depenedency Injection" where your class is not responsible to create its associated objects. Another concept here is "Decoupling": this means you use the interface (not the actual implementation) to decalre you class fields. This is important because you may have different implementations of the same service interface, therefore, you don't couple your class with one implementation. For example, insted of using:


Spring container allows you to inject the actual implementation using beans configuration file.

SCJP 90%<br />FileNet Certified Professional: Content Management Developer 92%<br />FileNet Certified Professional: Business Process Management Developer 92%
I agree. Here's the link:
subject: using setter method in spring
It's not a secret anymore!