title: Spring Scoped Proxy working for fields of the Scoped Proxy Beans fields but not the beans itself?
body: <p>This is the code I have:</p>
  
  <p>SpringConfiguration:</p>
  
  <pre><code>package biz.tugay;
  /* User: koray@tugay.biz Date: 25/12/15 Time: 19:30 */
  
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  @ComponentScan(basePackages = "biz.tugay")
  public class SpringConfiguration {
  }
  </code></pre>
  
  <p>Foo:</p>
  
  <pre><code>package biz.tugay;
  /* User: koray@tugay.biz Date: 25/12/15 Time: 19:36 */
  
  public interface Foo {
      String getState();
  }
  </code></pre>
  
  <p>FooImpl:</p>
  
  <pre><code>package biz.tugay;
  /* User: koray@tugay.biz Date: 25/12/15 Time: 19:31 */
  
  import org.springframework.context.annotation.Scope;
  import org.springframework.context.annotation.ScopedProxyMode;
  import org.springframework.stereotype.Component;
  
  import java.util.UUID;
  
  @Component
  @Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
  public class FooImpl implements Foo {
      private final String state = UUID.randomUUID().toString();
      public String getState() {
          return state;
      }
  }
  </code></pre>
  
  <p>Bar:</p>
  
  <pre><code>package biz.tugay;
  /* User: koray@tugay.biz Date: 25/12/15 Time: 19:35 */
  
  public interface Bar {
      Foo getFoo();
  }
  </code></pre>
  
  <p>BarImpl:</p>
  
  <pre><code>package biz.tugay;
  /* User: koray@tugay.biz Date: 25/12/15 Time: 19:33 */
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Scope;
  import org.springframework.stereotype.Component;
  
  @Component
  @Scope(value = "singleton")
  public class BarImpl implements Bar {
  
      private Foo foo;
  
      @Autowired
      public void setFoo(Foo foo) {
          this.foo = foo;
      }
  
      public Foo getFoo() {
          return foo;
      }
  }
  </code></pre>
  
  <p>and the Test Class:</p>
  
  <pre><code>package biz.tugay;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  
  import static java.lang.System.out;
  
  public class TestClass {
  
      final static Class&lt;SpringConfiguration&gt; SPRING_CONFIGURATION_CLASS = SpringConfiguration.class;
  
      public static void main(String[] args) {
  
          final ApplicationContext applicationContext;
          applicationContext = new AnnotationConfigApplicationContext(SPRING_CONFIGURATION_CLASS);
  
          final Bar barOne = applicationContext.getBean(BarImpl.class);
          final Bar barTwo = applicationContext.getBean(BarImpl.class);
  
          out.println("barOne == barTwo: " + (barOne == barTwo));
          out.println("barOne.getFoo == barTwo.getFoo: " + (barOne.getFoo() == barTwo.getFoo()));
  
          out.println(barOne.getFoo().getState());
          out.println(barTwo.getFoo().getState());
  
      }
  }
  </code></pre>
  
  <p>And the output will be:</p>
  
  <pre><code>barOne == barTwo: true
  barOne.getFoo == barTwo.getFoo: true
  064bdb74-cad7-4d13-86fe-a4fc0021e5a0
  c6f2d9be-09b4-456d-9414-8ece2f2acc9e
  </code></pre>
  
  <p>My question is,</p>
  
  <p>I understand that 064bdb74-cad7-4d13-86fe-a4fc0021e5a0 is not equal to c6f2d9be-09b4-456d-9414-8ece2f2acc9e because FooImpl is actually ScopedProxy. </p>
  
  <p>What I do not understand is, how come barOne.getFoo can be equal to barTwo.getFoo? </p>
  
  <p>How is this possible:</p>
  
  <pre><code>barOne.getFoo() == barTwo.getFoo()
  barOne.getFoo().getState() != barTwo().getFoo().getState()
  </code></pre>
  
  <p>???</p>