title: best practices of using bean scopes in spring mvc application
body: <p>I have seen it written at many places that DAO and Service classes of a spring application should be <strong>singleton</strong> scoped.<br>
  In my application I have the following service class  </p>
  
  <pre><code>@Service
  public class CustomerServiceImpl implements CustomerService {
  
      @Autowired
      private CustomerDAO customerDAO;
  
      .......
      parameterised methods only....
  }  
  </code></pre>
  
  <p>and a DAO class  </p>
  
  <pre><code>@Repository
  public class CustomerDAOImpl implements CustomerDAO {
  
  @Autowired
  private SessionFactory sessionFactory;
  
  ...............
  parameterised methods only....
  }  
  </code></pre>
  
  <p>Since I haven't defined any scope, the default scope is singleton.So both the CustomerService and CustomerDAO will be instantiated only once per the container.Also the DAO class will be autowired to the Service class only once at the beginning.Since it is going to be a <strong><em>heavy request</em></strong> web application, that means (<strong>OR</strong> does that mean <strong>?</strong>) <em>hundreds of threads are going to use the same instances of both the classes.</em>  </p>
  
  <p>Then how <strong>thread safety</strong> is guaranteed in this case ?<br>
  And what about the scope of hibernate sessionfactory bean defined in the xml ?  </p>
  
  <p>I am very much confused about the bean scopes and thread safety in a spring mvc application. Springsource documentation doesn't clearly explain these for a web application.  </p>
  
  <p>Could anyone please explain me the best practises of using bean scopes(for DAO, Service, Controller and other beans) for a heavy request web application ?<br>
  Any link which explains these woulb be grateful for me.  </p>
  
  <p>Thanks for your suggestions in advance.</p>