Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6080687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:05:25+00:00 2026-05-23T11:05:25+00:00

i am bit confused among the 3 scopes i.e request, prototype and singleton explained

  • 0

i am bit confused among the 3 scopes i.e request, prototype and singleton explained at
http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch04s04.html. My doubts are:-

RequestScope :-say a web request comes from client, In the same request we are creating the bean with statement factory.getBean(“MyBean1”)
will it return two different instances. My understanding is it will return the same instance as it is done under the same http request. Right? While it will return the two different
instances in case of prototype request. Correct?

Prototype:- Itis results in the creation of a new bean instance every time a request for that specific bean is made.
As a rule of thumb, you should use the prototype scope for all beans that are stateful, while the singleton scope should be used for stateless beans.
How come its differnt from request scope and how its support for stateful beans.

Singleton:- its written under section under 4.4.1.

Please be aware that Spring’s concept of a singleton bean is quite different from the Singleton pattern as defined in the seminal
Gang of Four (GoF) patterns book. The GoF Singleton hardcodes the scope of an object such that one and only one instance of a particular
class will ever be created per ClassLoader. The scope of the Spring singleton is best described as per container and per bean.

My question here is on statement “The scope of the Spring singleton is best described as per container and per bean”

per container:-Can we have more than one core conatiner in any application? My understanding is
that if we are creating BeanFactory factory = new XmlBeanFactory(“MyXml”) two times in an applicaton , we can say two container instance exist.Right?
in this case we can two instances of bean even if it is declared singleton. Is this correct?

It is stated on some websites that it is stated that Spring core container avoid the need of programming the singleton. Here do they mean we dont have to code for singleton container
will provide it for us. Right? Question here is If we declare the public constructor in bean. will container still provide the singleton for that bean(scope is singleton in xml file for this bean)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:05:25+00:00Added an answer on May 23, 2026 at 11:05 am

    RequestScope :-say a web request comes from client, In the same request we are creating the bean with statement factory.getBean(“MyBean1”) will it return two different instances. My understanding is it will return the same instance as it is done under the same http request. Right? While it will return the two different instances in case of prototype request. Correct?

    Correct.

    Prototype:- Itis results in the creation of a new bean instance every time a request for that specific bean is made. As a rule of thumb, you should use the prototype scope for all beans that are stateful, while the singleton scope should be used for stateless beans. How come its differnt from request scope and how its support for stateful beans.

    All scopes support stateful beans, it’s just that you need to be very careful about managing that state. You need to think carefully about deciding the scope of that state. Is the state local to the current request, or is it local to the method that calls getBean? There is no difference in how the various scopes treat stateful beans.

    per container:-Can we have more than one core conatiner in any application? My understanding is that if we are creating BeanFactory factory = new XmlBeanFactory(“MyXml”) two times in an applicaton , we can say two container instance exist.Right? in this case we can two instances of bean even if it is declared singleton. Is this correct?

    Yes, that’s correct. The “singleton” is preserved only as long as you ask the container for the bean, and that there is only one container defining that bean.

    It is stated on some websites that it is stated that Spring core container avoid the need of programming the singleton. Here do they mean we dont have to code for singleton container will provide it for us. Right? Question here is If we declare the public constructor in bean. will container still provide the singleton for that bean(scope is singleton in xml file for this bean)?

    If you simply call new MyBean(), when MyBean is defined as a bean in Spring, then the singleton will not be preserved. Spring has no control of things that you do outside of the container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about how an object could be edited with Spring Forms,
Bit confused here, I have an on-demand instance but do I get charged even
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused here. Microsoft as far as I can tell claims that
I'm a bit confused that the argument to crypto functions is a string. Should
I am a bit confused why this code compiles. I leave out the necessary
I'm a bit confused from what I've heard Java doesn't do events. But I
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused over the .net redistributables... Our C# code uses some API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.