How does spring manage these objects internally?
When are the singleton objects created and destroyed?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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