title: Tomcat - How exactly context path matching works?
body: <p>Suppose I have two Spring webapps deployed to the same Tomcat server instance:</p>
  
  <p><strong>A:</strong></p>
  
  <p><code>ROOT.war, context = /</code></p>
  
  <pre><code>@Controller
  class TestController {
  
      @RequestMapping("/api/someMethod")
      public String someMethod() {
          //..
      }
  
      @RequestMapping("/api/v1/someMethod")
      public String someMethod() {
          //..
      }
  }
  </code></pre>
  
  <p><strong>B:</strong></p>
  
  <p><code>api#v1.war, context = /api/v1/</code></p>
  
  <pre><code>@Controller
  class TestController {
  
      @RequestMapping("/someMethod")
      public String someMethod() {
          //..
      }
  }
  </code></pre>
  
  <p>Which web application will be used to process the following HTTP requests?</p>
  
  <p><code>GET http://&lt;hostname&gt;/api/someMethod</code></p>
  
  <p><code>GET http://&lt;hostname&gt;/api/v1/someMethod</code></p>
  
  <p><code>GET http://&lt;hostname&gt;/api/v1/nonexistentMethod</code></p>
  
  <p>As you can see the second HTTP request matches both apps. I have tried to find answer in <a href="https://tomcat.apache.org/tomcat-7.0-doc/config/context.html" rel="nofollow">Tomcat docs</a>, but found none. Where is specified how context path matching works?</p>