title: Circular Reference in Spring with a composite pattern
body: <p>let's say that I have structure like this : 
  <img src="https://i.stack.imgur.com/TxEpe.png" alt="Composite Pattern"></p>
  
  <p>As most you may see it, it's a composite pattern. How do instantiate this pattern using Spring? For instance, if I have the following code :</p>
  
  <pre><code>&lt;bean id="leaf1"&gt;
     &lt;constructor-arg name="Name" value="leaf1" /&gt;
  &lt;/bean&gt;
   &lt;bean id="leaf2"&gt;
     &lt;constructor-arg name="Name" value="leaf2" /&gt;
  &lt;/bean&gt;
  &lt;bean id="leaf3"&gt;
     &lt;constructor-arg name="Name" value="leaf3" /&gt;
  &lt;/bean&gt;
  &lt;bean id="composite1"&gt;
      &lt;constructor-arg&gt;
          &lt;set&gt;
              &lt;ref bean="composite2" /&gt;
              &lt;ref bean="leaf2" /&gt;
          &lt;/set&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  &lt;bean id="composite2"&gt;
      &lt;constructor-arg&gt;
          &lt;set&gt;
              &lt;ref bean="leaf3" /&gt;
                           &lt;ref bean="leaf1" /&gt; 
          &lt;/set&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>As you may see here, this configuration will raise and <code>org.springframework.beans.factory.BeanCreationException</code> because there is a circular reference. A composite contains a list of Component and a component is composed of Leaf and Composite. How do I solve this problem using Spring?</p>