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 8697487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:32:17+00:00 2026-06-13T01:32:17+00:00

Spring reference manual says: The scope of the Spring singleton is best described as

  • 0

Spring reference manual says:

The scope of the Spring singleton is best described as “per container and per bean”.

consider this code snippet:

ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml")
MyBean myobj=(MyBean)context.getBean("myBean"); //myBean is of singleton scope.
MyBean myobj1=(MyBean)context.getBean("myBean");

per container means that if we do context.getBean("myBean"); twice it will return same bean i.e. myobj==myobj1 is true.

But what does per bean in per container and per bean from above statement means?

  • 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-06-13T01:32:18+00:00Added an answer on June 13, 2026 at 1:32 am

    I asked another question in reference to this one:spring singleton scope— per container per bean

    From that I concluded following for per bean part of phrase per container per bean:

    Consider:

    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml")
    MyBean myobj=(MyBean)context.getBean("myBean"); 
    MyBean myobj1=(MyBean)context.getBean("myBean"); 
    MyBean myobj2=(MyBean)context.getBean("mySecondBean");
    

    Beans.xml:

    <bean id="myBean" class="MyBean"/>
    <bean id="mySecondBean" class="MyBean"/>
    

    Now Singleton in Spring is per container per bean.

    per container means if we get same bean id by getBean() within same container then they represent same instances.Therefore myobj==myobj1 is true.

    And if we get bean with same id in two different containers then they will represent two different instances.This is represented in answer above given by Nirmal- thInk beYond.

    But for singleton, within per container it should also be per bean(per bean tag).

    i.e if we define two beans in configuration file of same class then they represent different instances even within same container.

    Thats why myobj==myobj2 is false.

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

Sidebar

Related Questions

I am asking this Question in reference to my question: spring singleton scope Spring
I've implemented authentication through WS-Security on my webservice as described at http://static.springframework.org/spring-ws/sites/1.5/reference/html/security.html , like
Hallo all: I read the spring reference about this point. I would choose to
I am in reference to Spring Roo In Action (book from Manning). Somewhere in
Following the spring-security documentation: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html I am trying to set up ldap authentication (very
I want to use Spring 3 for validation. In the reference documentation, section 6.2
I've got my first impression of Spring WebFlow 2.1 from studying the reference app
I suppose that this is an interesting code example. We have a class --
There is a @Bean annotation in Spring 3.0. It allows to define a Spring
According to the Doctrine manual I should be able to reference an attribute of

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.