title: Initialize Spring Bean as late as possible
body: <p>I have a follofing situation int "super-context.xml":</p>
  
  <pre><code>&lt;bean id="conf" class="ee.Conf"/&gt;
  
  &lt;bean id="service" class="ee.Serivce"&gt;
    &lt;property name="conf" ref="conf"&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now I want to use this "super-context.xml" in various different projects. Say "sub-context.xml" has:</p>
  
  <pre><code>&lt;import resource="super-context.xml"/&gt;
  
  &lt;bean id="subConf1" class="ee.SubConf"&gt;
     &lt;property name="confloc" value="classpath:ee/customconf1.sss" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="subConf2" class="ee.SubConf"&gt;
     &lt;property name="confloc" value="classpath:ee/customconf2.sss" /&gt;
  &lt;/bean&gt;
  
  ...
  
  &lt;bean id="subConfn" class="ee.SubConf"&gt;
     &lt;property name="confloc" value="classpath:ee/customconfn.sss" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>ee.Conf is something as follows:</p>
  
  <pre><code>public class Conf ... {
      ...
      public void addSubConf(Resource res) {
         //configuration resolving from res
      }
      ...
  } 
  </code></pre>
  
  <p>ee.SubConf is something as follows:</p>
  
  <pre><code>public class SubConf ... {
      ...
      @Autowired
      ee.Conf superConf;
      ...
      public void setConfloc(Resource res) {
         superConf.addSubConf(res);
      }
      ...
  }
  </code></pre>
  
  <p>The problem aries on context load. Beans are initialized in following order (due to ordering in context file): conf, service, subConf1, subConf2, ... subConfn</p>
  
  <p>But service bean actually depends on all the subConf beans (although this can't be deducted from the context definition itself). It loads OK when import in "sub-context.xml" is added after subConf bean definitions.</p>
  
  <p>Reason behind this is implementing modularity. Is it possible to force a bean to load as late as possible ("service" bean in the example) or make beans of certain type load as soon as possible ("subConf" beans in the example), since fixed ordering of beans in "sub-context.xml" partly kills the wished modularity</p>
  
  <p>Or is theree a more pure way to achieve this type of modularity?</p>