title: Multiple jersey servlets in one single web.xml
body: <p>Is it possible to have multiple jersey servlets in one single web.xml? I am trying to do the RESTfull versioning in this way:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
  
    &lt;display-name&gt;myapi&lt;/display-name&gt;
  
    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/context-v1.xml /WEB-INF/context-v2.xml&lt;/param-value&gt;
    &lt;/context-param&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;REST-V1&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.spring.container.servlet.SpringServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
        &lt;param-value&gt;com.myapi.rest.v1&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;REST-V1&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/v1/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;REST-V2&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.spring.container.servlet.SpringServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
        &lt;param-value&gt;com.myapi.rest.v2&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;REST-V2&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/v2/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>But the spring context-v1 and context-v2 should be loaded separately? Because they have beans, which have the same name etc.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>If you look in my console output it's loading the resources (admin/info) two times for each servlet:</p>
  
  <pre><code>15.07.2012 14:47:08 com.sun.jersey.api.core.PackagesResourceConfig init
  INFO: Scanning for root resource and provider classes in the packages:
    com.myapi.rest.v1
  15.07.2012 14:47:08 com.sun.jersey.api.core.ScanningResourceConfig logClasses
  INFO: Root resource classes found:
    class com.myapi.rest.v1.LOAdminResource
    class com.myapi.rest.v1.LOInfoResource
  15.07.2012 14:47:08 com.sun.jersey.api.core.ScanningResourceConfig init
  INFO: No provider classes found.
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
  INFO: Using default applicationContext
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, adminResource_v2, of type com.myapi.rest.v2.LOAdminResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, infoResource_v2, of type com.myapi.rest.v2.LOInfoResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, adminResource_v1, of type com.myapi.rest.v1.LOAdminResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, infoResource_v1, of type com.myapi.rest.v1.LOInfoResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
  INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
  15.07.2012 14:47:09 com.sun.jersey.api.core.PackagesResourceConfig init
  INFO: Scanning for root resource and provider classes in the packages:
    com.myapi.rest.v2
  15.07.2012 14:47:09 com.sun.jersey.api.core.ScanningResourceConfig logClasses
  INFO: Root resource classes found:
    class com.myapi.rest.v2.LOAdminResource
    class com.myapi.rest.v2.LOInfoResource
  15.07.2012 14:47:09 com.sun.jersey.api.core.ScanningResourceConfig init
  INFO: No provider classes found.
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
  INFO: Using default applicationContext
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, adminResource_v2, of type com.myapi.rest.v2.LOAdminResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, infoResource_v2, of type com.myapi.rest.v2.LOInfoResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, adminResource_v1, of type com.myapi.rest.v1.LOAdminResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
  INFO: Registering Spring bean, infoResource_v1, of type com.myapi.rest.v1.LOInfoResource as a root resource class
  15.07.2012 14:47:09 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
  INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
  </code></pre>