title: spring singleton scope-- per container per bean
body: <p>I am asking this Question in reference to my question:</p>
  
  <p><a href="https://stackoverflow.com/questions/11631047/spring-singleton-scope">spring singleton scope</a></p>
  
  <p>Spring singleton is defined in reference manual as <strong>per container per bean</strong>.</p>
  
  <p><strong>per container</strong> means if we do like:</p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml")
  MyBean myobj=(MyBean)context.getBean("myBean"); //myBean is of singleton scope.
  MyBean myobj1=(MyBean)context.getBean("myBean");
  </code></pre>
  
  <p><strong>Beans.xml:</strong></p>
  
  <pre><code>&lt;bean id="myBean" class="MyBean"/&gt;
  </code></pre>
  
  <p>Then <code>myobj==myobj1</code> will come out to true.Means both pointing to <em>same instance</em>.</p>
  
  <p>For <strong>per bean</strong> part of phrase <strong>per container per bean</strong> i was somewhat confused. Am i right in following for <strong>per bean</strong> :</p>
  
  <p>If we do like </p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml")
  MyBean myobj=(MyBean)context.getBean("myBean"); 
  MyBean myobj1=(MyBean)context.getBean("mySecondBean");
  </code></pre>
  
  <p><strong>Beans.xml:</strong></p>
  
  <pre><code>&lt;bean id="myBean" class="MyBean"/&gt;
  &lt;bean id="mySecondBean" class="MyBean"/&gt;
  </code></pre>
  
  <p>Then <code>myobj==myobj1</code> will come out to false. Means then they are <em>two different instances</em>?</p>