开发者

Does spring dependency injection create singleton objects?

开发者 https://www.devze.com 2023-01-14 14:28 出处:网络
How does spring manage these objects 开发者_开发问答internally? When are the singleton objects created and destroyed?By default, Spring beans are basically singletons.Spring will create a single inst

How does spring manage these objects 开发者_开发问答internally?

When are the singleton objects created and destroyed?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号