title: How to autowire bean in same bean
body: <p>I would like to autowire instance of bean A to the same instance of A. How can I achieve this with annotation (without XML).</p>
  
  <p>Example:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class A {
  
      @Autowire
      A a;
  
  }
  </code></pre>
  
  <p>I also tried</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class A {
  
      A a;
  
      @Autowired
      public void setA(final A a) {
          this.a = a;
      }
  
  }
  </code></pre>
  
  <p>but it is not working too :-/</p>
  
  <p>Configuration using XML like</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="a" class="A"&gt;
      &lt;property name="a" ref="a" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>works fine. And also it's possible to use</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class A implements InitializingBean {
  
      A a;
  
      @Autowired
      ApplicationContext ctx;
  
      @Override
      public void afterPropertiesSet() throws Exception {
          a = ctx.getBean(A.class);
      }
  
  }
  </code></pre>
  
  <p>but this is cumbersome. The strange thing is, that Spring can handle this when using XML configuration, but not when using annotation-based one.</p>