title: Spring singleton created multiple times
body: <p>I have a bean defined in my spring web application and I am expecting to have only one instance of this bean, here is my bean definition:</p>
  
  <pre><code>&lt;bean id="accessControl" class="my.spring.app.AccessControl" /&gt;
  </code></pre>
  
  <p>In the constructor of AccessControl, I assign an identifier to the object, something like this:</p>
  
  <pre><code>public class AccessControl {
     private long id = 0;
     public AccessControl() {
          id = System.currentTimeMillis();
     }
  
     public long getAccessControlId() {
          return id;
     }
  }
  </code></pre>
  
  <p>In a different class, I try to get hold of the instance of AccessControl, something like this:</p>
  
  <pre><code>            ApplicationContext ctx =
                       new ClassPathXmlApplicationContext("acbean.xml");
  
              AccessControl ac = (AccessControl) ctx.getBean("accessControl");
              LOGGER_.info("AccessControl Identifier : " + ac.getAccessControlId());
  </code></pre>
  
  <p>I am expecting the "id" value to be the same because the value of "id" is set in the constructor and constructor should not get called again and again but that is exactly what is happening. Infact, I added a log statement to the constructor and a new object is created everytime.</p>
  
  <p>I have read: <a href="http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/" rel="noreferrer">http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/</a>
  but I don't think I am dealing with the same class defined twice with two different bean identifiers and the application context is the same.</p>
  
  <p>Can anyone share what is wrong with the way I have defined the bean?</p>
  
  <p>I have also experimented with singleton="true" and scope="singleton" but they do not make any differece.</p>
  
  <p>Thanks.</p>