title: How to set OsgiBundleXmlApplicationContext as parent of WebApplicationContext
body: <p>In my Camel (2.14.0) application I use Spring Web Services to trigger Camel routes. The artifact is built as an OSGi bundle and deployed in Karaf (3.0.2).</p>
  
  <p>For the first version I configured spring-ws to use the JVM internal web server through the <code>org.springframework.remoting.support.SimpleHttpServerFactoryBean</code> to expose the web service. This works just fine. But is not very OSGi-ish. So instead I would like to publish the <code>org.springframework.ws.transport.http.MessageDispatcherServlet</code> as a service to the <a href="https://ops4j1.jira.com/wiki/display/ops4j/Pax+Web+Extender+-+Whiteboard" rel="nofollow">Karaf whiteboard extender</a> like so:</p>
  
  <pre><code>&lt;bean id="pas-ws-patient-servlet" class="org.springframework.ws.transport.http.MessageDispatcherServlet"&gt;
      &lt;property name="contextConfigLocation" value="/endpoint-mapping.xml" /&gt; 
  &lt;/bean&gt;
  
  &lt;osgi:service ref="pas-ws-patient-servlet" interface="javax.servlet.http.HttpServlet"&gt;
      &lt;service-properties&gt;
          &lt;entry key="alias" value="/${pas.ws.patient.contextroot}" /&gt;
      &lt;/service-properties&gt;
  &lt;/osgi:service&gt;
  </code></pre>
  
  <p>Which works like a charm for "regular" servlets. But the <code>MessageDispatcherServlet</code> wants to build its own <code>WebApplicationContext</code> and expects to find a bean of type <code>org.springframework.ws.server.EndpointMapping</code> in that context. Camel provides an implementation of <code>EndpointMapping</code> that has to be used with its spring-ws component. </p>
  
  <p>The problem I am facing is that the same instance of the endpoint mapping bean must be shared between the <code>OsgiBundleXmlApplicationContext</code> that creates the Camel context and the application context created by the <code>MessageDispatcherServlet</code>. Which would be the case if my <code>OsgiBundleXmlApplicationContext</code> was the parent of the <code>WebApplicationContext</code>. Though how to set the parent context of the <code>WebApplicationContext</code> to the "current" context from which I am publishing the servlet as a service eludes me.</p>
  
  <p>Instantiating a <code>WebApplicationContext</code> from within the <code>OsgiBundleXmlApplicationContext</code> to pass it to the MessageDispatcherServlet gives me an exception: </p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext
  </code></pre>
  
  <p>Unfortunately the <code>WebServiceMessageReceiver</code> (which encapsulates the <code>EndpointMapping</code>) of the <code>MessageDispatcherServlet</code> is a private member. So I cannot set the mapping bean either in a straight forward way.</p>
  
  <p>Is there a way to create the context hierarchy? Or can a bean instance be shared across contexts in another way?</p>