title: Spring - Injecting main bean into property bean
body: <p>I am trying to configure such a relation in spring:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>MyObject myObject = new MyObject();
  myObject.setEntity( new Entity(this) );
  </code></pre>
  
  <p>is it possible?</p>
  
  <p>When I am trying such a configuration:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="myObject" class="MyObject" scope="request"&gt;
      &lt;property name="entity"&gt;
          &lt;bean class="Entity"&gt;
              &lt;constructor-arg ref="myObject"/&gt;
           &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>It returns:
  
      [java] Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'myObject': Requested bean is currently in creation: Is there an unresolvable circular reference?</p>
  
  <p>I am thinking about using factory-method for this, but maybe someone has better idea?</p>