title: Spring web app. One war multiple application context
body: <p>I searched for a while but can't manage to find a proper solution to my problem.</p>
  
  <p>I have one WAR web application and I want 2 spring applications running in it one for the web-part, one running scheduled task.
  Both applications share a lot of beans so I would like that those two applications share some beans instance.</p>
  
  <p>I'd like to split my contexts in:
  <br/>-shared-context.xml
  <br/>-web-context.xml
  <br/>-task-context.xml</p>
  
  <p>Web-context and task-context must be isolated and not see each other. They need to create a few beans that are the same but have different configs.</p>
  
  <p>Is this possible? And how should I do it?</p>
  
  <p>I tried first to put <code>&lt;import resource="classpath:shared-context.xml" /&gt;</code> in both web-context and task context and to configure my web.xml as </p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;web-context.xml task-context.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>but the problem is that there is no isolation between web and task. They all share all the beans even the one defined in web-context.xml and task-context.xml</p>
  
  <p>For info here is my web.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/web-context.xml /WEB-INF/task-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Listeners --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.gwtrpcspring.RemoteServiceDispatcher&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;contentDownloadServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;ch.olator.servlet.MyContentDownloadServlet&lt;/servlet-class&gt; 
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.rpc&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;contentDownloadServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/download&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      ... some irrelevant filters ...
  
  &lt;/web-app&gt;
  </code></pre>
  
  
  
  <p><strong>UPDATED</strong> <br/>
  -To make things clearer I need this isolation between task and web because the task-context which is used to run scheduled task to define some beans that are in web-context but differently. E.g. I have scoped-session beans that are in web-context but I need to define them differently for the tasks as scheduled task can't use scoped-session beans.</p>