title: understanding of spring bean scopes in a web application
body: <p>As per <code>springsource</code> documentation a <code>singleton</code> scoped bean is instantiated only once per<br>
  container. For example I have a singleton scoped <code>UserDetails</code> bean which contains information<br>
  about a user.<br>
  In my main() method:  </p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"Spring-Customer.xml"});  
  UserDetails ud1 = (UserDetails)context.getBean("userDetails");  
  custA.setAddress("Address set by ud1");  
  System.out.println("Address : " + ud1.getAddress());  
  
  UserDetails ud2 = (UserDetails)context.getBean("userDetails");  
  System.out.println("Address : " + ud2.getAddress());
  </code></pre>
  
  <p>The output will be  </p>
  
  <pre><code>Address set by ud1  
  Address set by ud1
  </code></pre>
  
  <p>Because of userDetails is a singleton bean, the second retrieval by <code>ud2</code> will give the same result as that of ud1.  </p>
  
  <p><strong>NOW</strong> here is my problem:<br>
  For my web application I have the following <code>UserDetails</code> bean in my <code>dispatcher-servlet.xml.</code>  </p>
  
  <pre><code>&lt;bean id="userDetails" class="com.mukund.DTO.UserDetails" /&gt;  
  </code></pre>
  
  <p><strong>first question:</strong> is singleton scope is the default for a web application too ?<br>
  IF YES:<br>
  This bean is autowired into <code>AccountService</code> and <code>CustomerService</code> classes.<br>
  If a client say <code>clientA</code> has set the <strong>first name</strong> of the user to <strong>"UserA"</strong> in CustomerService class and after some time it retrieves the first name from AccountService class,  </p>
  
  <p><strong>second question:</strong> does it get the <strong>same</strong> instance of UserDetails with "UserA" as the first name ?<br>
  <strong>third question:</strong> In the mean time if another client say <code>clientB</code> tries to get the first name in AccountService class will it get "UserA" ?<br>
  <strong>fourth question:</strong> will the same UserDetails instance be shared by clientA, clientB and others ? If yes: what scope to choose prototype, request or session.  </p>
  
  <p><em>I hope you understand my point. Please explain me spring bean scopes with regards to a web application.</em>  </p>
  
  <p>THANKS</p>