Skip to main content

Spring - Bean Scopes

What is spring Bean scopes ?

it is just an interview question which i have faced!!! A simple one.... Any way i couldn't answer it . 

For the sake of next interview i am going to answer it in here:

When defining a <bean> 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. Similar way 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 following five scopes, three of which are available only if you use a web-aware ApplicationContext.

ScopeDescription
singletonThis scopes the bean definition to a single instance per Spring IoC container (default).
prototypeThis scopes a single bean definition to have any number of object instances.
requestThis scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
sessionThis scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
global-sessionThis scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.

Comments


  1. Really Good blog post.provided a helpful information about bean scopes .keep updating...
    Digital marketing company in Chennai

    ReplyDelete
  2. Interesting blog about spring bean scopes which attracted me more.Spend a worthful time.keep updating more.
    MSBI Training in Chennai

    ReplyDelete
  3. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.

    Eczema Treatment

    ReplyDelete
  4. I must thank you for the efforts you have put in spending this site. I am hoping to out the same high-grade content by you later on as well. In truth, your creative writing abilities has inspired me to get my own, personal blog now..
    Java Training in Chennai
    Dot Net Training in Chennai
    Cloud Computing Training in Chennai
    Digital Marketing Training in Chennai
    SAS Training in Chennai
    SEO Training in Chennai
    AWS Training in Chennai
    Microsoft Azure Training in Chennai



    ReplyDelete

Post a Comment