Collection and sharing of, interview questions and answers asked in various interviews, faqs and articles.....
Spring – Bean Scopes
When defining a in Spring, you have the option of declaring a scope for that bean.
For example, to force Spring to produce a new bean instance each time one is needed,
you should declare the bean's scope attribute to be prototype. Similarly, if you want
Spring to return the same bean instance each time one is needed, you should declare the
bean's scope attribute to be singleton.
The Spring Framework supports the following five scopes, three of which are available only
if you use a web-aware ApplicationContext.
Scope Description
singleton This scopes the bean definition to a single instance per Spring IoC
container (default).
prototype
This scopes a single bean definition to have any number of object
instances.
request This scopes a bean definition to an HTTP request. Only valid in the
context of a web-aware Spring ApplicationContext.
session This scopes a bean definition to an HTTP session. Only valid in the
context of a web-aware Spring ApplicationContext.
global-session This scopes a bean definition to a global HTTP session. Only valid in the
context of a web-aware Spring ApplicationContext.
In this chapter, we will discuss about the first two scopes and the remaining three will be
discussed when we discuss about web-aware Spring ApplicationContext.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment