aspose file tools*
The moose likes Spring and the fly likes Dependency Injection with setter injection ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Dependency Injection with setter injection ?" Watch "Dependency Injection with setter injection ?" New topic
Author

Dependency Injection with setter injection ?

Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

hi All,

I am new to Spring . I was going through An article on spring injection dependency. I read following thing.

in case of Constructor Injection the dependencies are handed over at the time of object instantiation of the dependent objects whereas In case of Setter/Mutator Injection the dependencies are injected after the dependent object has already been created


If i have a Interface IUserService . Code is like that.



then please make me clear that is userService is a dependent component??
And let me know that who create the dependent object In context of following article.

Good luck!!
A small leak can sink a Gigantic ship.>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Spring handles object instantiation for either constructor or setter injection.
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

ok So, is userService in my case is the dependent component?

and does Spring first creates the object then injects the dependency for the dependent object?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Raza Mohd wrote:ok So, is userService in my case is the dependent component?

I don't know what that term means in this context.
and does Spring first creates the object then injects the dependency for the dependent object?

What do you think?
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

I think it first creates the object !
as we are calling a method findUser() without instantiating UserService class with implements IUserService.
how can a method be called without object.

it clears that Spring container manages the object instntiation .
 
wood burning stoves
 
subject: Dependency Injection with setter injection ?