title: Best way to "merge" two ApplicationContext configurations
body: <p>Here's the scenario:  </p>
  
  <p>I have a standard <code>applicationConfig.xml</code> spring configuration for a basic web app.  It works great.  I also have a "core jar" for one of our internal dependencies for a different app.  The "core jar" has an <code>AnnotationConfigApplicationContext</code> which registers the different <code>@Configuration</code> beans appropriately.  I'm trying to use the annotation <code>@Configuration</code> beans in the app which is configured using the <code>applicationConfig.xml</code>.</p>
  
  <p>I can dream up two options which I believe will work:</p>
  
  <ol>
  <li><p>Refactor the xml config to also use the annotationConfig and register the different configurations to the context the same way our "core jars" do.</p></li>
  <li><p>Create a second context and access it directly instead of having the singletons/prototypes live on the same applicationContext as the xml config.  I'd really rather not do this as it seems more like a hack than an elegant solution (and I'm not entirely sure it would behave as I'd want it to.)</p></li>
  <li><p>What I'm dreaming of, but can't find any documentation to support</p></li>
  </ol>
  
  <p>I'd like to register the annotation configuration bean into the application context somehow, but I can't get the objects to line up the way I'd like them to (aka, my context won't <code>.register()</code> the <code>@Configuration</code> file - only 1 bean at a time....)</p>
  
  <p><strong>Just to follow up</strong> - I got this working (YAY).  In my case, I ended up following the general pattern set forth by gpeche.</p>
  
  <p>The applicationContext-parent.xml contained the 1 bean def:</p>
  
  <pre><code>&lt;bean id="parentApplicationContext" class="org.springframework.context.annotation.AnnotationConfigApplicationContext" scope="singleton"&gt;
      &lt;constructor-arg&gt;
        &lt;list&gt;
          &lt;value&gt;com.package.CoreCommonInContainerConfigImpl&lt;/value&gt;
          &lt;value&gt;com.package.CoreCommonCommonConfigImpl&lt;/value&gt;
        &lt;/list&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>where the CoreCommon****Impl classes are @Configuration annotated classes which define beans for that context.</p>
  
  <p>As gpeche noted, an @Autowired Bean bean; inside of a controller (for example)  falls back on the parent context and resolves automagically.</p>
  
  <p>THANKS!</p>