title: Spring MVC picks the wrong controller method
body: <p>In my application I have a situation where spring mvc consistently picks the wrong controller method to execute. the debug log from spring below shows the problem, it finds two matches one for my general purpose handle all unhanded mappings controller which is mapped to <code>/api/**</code> and one for the actual thing I am looking for <code>api/companies/2/records/cabinets/FileTypes/50/1</code> spring mvc then picks <code>/api/**</code> handler over the more specific handler that it found.</p>
  
  <p>My understanding of spring is that if there are two matches for a request mapping, then spring will pick the handle method with a longer url. Why is spring mvc picking the shorter mapping?</p>
  
  <p>Given the following mappings:</p>
  
  <ul>
  <li><code>/api/companies/{id}/records/cabinets/FileTypes/{fileTypeId}/{versionId}</code> mapped to method1</li>
  <li><code>/api/**</code> mapped to method2</li>
  </ul>
  
  <p>And the path <code>api/companies/2/records/cabinets/FileTypes/50/1</code> what should spring mvc pick as the handler method for the two above url.</p>
  
  <p>here are the relevant lines form the debug log.</p>
  
  <pre><code>17:58:49,858 DEBUG [DispatcherServlet] DispatcherServlet with name 'main' processing PUT request for [/web/api/companies/2/records/cabinets/FileTypes/50/1]
  17:58:49,858 TRACE [DispatcherServlet] Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@2b25f2be] in DispatcherServlet with name 'main'
  7:58:49,858 DEBUG [RequestMappingHandlerMapping] Looking up handler method for path /api/companies/2/records/cabinets/FileTypes/50/1
  17:58:49,859 TRACE [RequestMappingHandlerMapping] Found 2 matching mapping(s) for [/api/companies/2/records/cabinets/FileTypes/50/1] : [{[/api/**],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}, {[/api/companies/{id}/records/cabinets/FileTypes/{fileTypeId}/{versionId}],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}]
  </code></pre>