title: Understanding spring proxying
body: <p><a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-factory-scopes-other-injection" rel="nofollow">The Spring documentation</a> provides the following example to show us the reason why we need to define aop:scoped-proxy explicitly in beans of scope session, reques, etc.</p>
  
  <pre><code>&lt;bean id="userPreferences" class="com.foo.UserPreferences" scope="session"&gt;
      &lt;aop:scoped-proxy/&gt;
  &lt;/bean&gt;
  &lt;bean id="userManager" class="com.foo.UserManager"&gt;
      &lt;property name="userPreferences" ref="userPreferences"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>We need proxy here, because for each request to the <code>userPreferences</code> bean we want to delegate one to the actual session-scoped bean's instance. That's clear. But the documentation also said that this's a deafult behavior for <code>singletone/prototype</code> scoped beans.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>&lt;bean id="userPreferences" class="com.foo.UserPreferences" /&gt;
  &lt;bean id="userManager" class="com.foo.UserManager"&gt;
      &lt;property name="userPreferences" ref="userPreferences"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Why do we need in proxy in the case of <code>singletone</code>-scoped beans? Doesn't injecting and calling to proxy cause some performance overhead? </p>
  
  <p><strong><em>Question</em></strong>: For performance sakes, could we avoid injecting proxy and inject actual bean instances in the case of the <code>singletone</code>-scoped beans instead?</p>