title: Spring Context Hierarchy with Web Application Context
body: <p>I'm dealing with a Spring MVC web app that's bootstrapped using a <code>DispatcherServlet</code>. It creates a <code>XmlWebApplicationContext</code> which manages the whole application:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet
      &lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:springmvc-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <p>Now there are some modules that should be loaded at runtime using a <code>ContextSingletonBeanFactoryLocator</code>. Therefore every module has its own <code>ClasspathXmlApplicationContext</code>. So that a module could reference beans from the <code>XmlWebApplicationContext</code>, it should be attached to the <code>XmlWebApplicationContext</code> to form a Context Hierarchy  wherein the <code>XmlWebApplicationContext</code> should play the role of the parent and the <code>ClasspathXmlApplicationContext</code> of the module the role of the child context. Unfortunately I'm unable to connect them using</p>
  
  <pre><code>&lt;beans&gt;
      &lt;bean id="moduleContext"
          class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
          &lt;constructor-arg&gt;
              ...
          &lt;/constructor-arg&gt;
          &lt;constructor-arg ref="parentContext" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>because I've found no way so far to give the <code>WebApplicationContext</code> the name <code>parentContext</code>. Have I overlooked something or is there a better/easier way to achieve the same in a different fashion?</p>