title: How to Avoid Initialisation of Spring's Default RequestMappingHandlerMapping?
body: <p>In order to implement our solution for versioning of request mappings I implemented my own <code>RequestMappingHandlerMapping</code> as a subclass of it. I overrode <code>registerHandlerMethod()</code> and <code>lookupHandlerMethod()</code>. The key concept is that one request mapping can appear multiple times, but the various implementations are stored in different Java-packages. My new class picks the required version from the correct package based on the first path element of the servlet path, which is the version number. The version is removed before looking for the proper request mapping handler.</p>
  
  <p>This is how I weave it into Spring:</p>
  
  <pre class="lang-java prettyprint-override"><code>import javax.inject.Inject;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
  import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
  
  @Configuration
  public class VersioningWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
  
    private VersioningRequestMappingHandlerMapping requestMappingHandlerMapping;
  
    @Override
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
      requestMappingHandlerMapping.setOrder(0);
      requestMappingHandlerMapping.setInterceptors(getInterceptors());
      return requestMappingHandlerMapping;
    }
  
    @Inject
    public void setRequestMappingHandlerMapping(VersioningRequestMappingHandlerMapping requestMappingHandlerMapping) {
      this.requestMappingHandlerMapping = requestMappingHandlerMapping;
    }
  
  }
  </code></pre>
  
  <p>The IMHO important bits of my applicationContext.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>  &lt;context:annotation-config /&gt;
    &lt;context:mbean-export /&gt;
    &lt;context:component-scan base-package="..." /&gt;
    &lt;mvc:annotation-driven /&gt;
  </code></pre>
  
  <p><em>Let me know if you want me to look for some other lines there.</em></p>
  
  <p>My problem is that my code runs through correctly, duplicates are handled properly. However, the original (?) <code>RequestMappingHandlerMapping</code> still gets initialised. That one fails due to the duplicate request mappings.</p>
  
  <p>How can I avoid this? The way I see it, my web-app would run nicely without the default <code>RequestMappingHandlerMapping</code>.</p>