views:

36

answers:

1

I want to know , Is spring dependency injection create singleton object ? If yes how it manage internally? ..

I want to know at what time this singleton object is created and destroy.

A: 

By default, Spring beans are basically singletons. Spring will create a single instance of each of your classes, and it will generally do this when Spring is initialized.

However, this is nearly infinitely customizable. Spring can also create a new instance of a bean whenever you ask for that bean by name, or it can create beans for the length of a request, or it can use a singleton but not instantiate it until the first time you invoke it, or several other things.

The discussion of when beans are instantiated and how long they last is a discussion of a bean's "Scope". Check it out in the documentation: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-scopes

CaptainAwesomePants
thanks , It means i have defined same bean with two different name in spring the IOC container creates two objects which have the spring singleton scope....???
Parag
yes, although I suppose the terminology would be that you have defined two different beans of the same class.
CaptainAwesomePants