title: spring mvc website on  root ("/")
body: <p>I want to map spring mvc controller to root (<code>/**</code>) path (and not sub-folder such as "/something") while making exceptions with <code>mvc:resources</code> (open to another method).</p>
  
  <p>This should be the ABC of that framework but apparently is a very complicated stuff to ask of it.</p>
  
  <p>My <code>app-servlet.xml</code> has these obvious mapping exceptions:</p>
  
  <pre><code>&lt;mvc:resources mapping="/favicon.ico" location="/favicon.ico" /&gt;
  &lt;mvc:resources mapping="/robots.txt" location="/robots.txt" /&gt;
  </code></pre>
  
  <p>And I have this controller:</p>
  
  <pre><code>import java.util.Date;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  @RequestMapping("/**")
  public class MainController {
  
      @RequestMapping(method = RequestMethod.GET)
      public String service(final HttpServletRequest request) {
          final String servlet_path = request.getServletPath();
          System.out.println(String.format("%s %s", new Date().toString(), servlet_path));
          return "test";
      }
  }
  </code></pre>
  
  <p>Now when I hit "/" or "/test" or "/test/page" I get output like:</p>
  
  <pre><code>Fri Aug 03 00:22:12 IDT 2012 /
  Fri Aug 03 00:22:13 IDT 2012 /favicon.ico
  </code></pre>
  
  <p>.. see? <code>service()</code> is being called for <code>/favicon.ico</code> even when it's explicitly excluded!</p>
  
  <p>Now I guess there's some "priority" to the <code>@Controller</code> over the XML, still, how do I make the exclusion work?</p>
  
  <p>A simple requirement - have the website on "/".</p>
  
  <p>P.S <a href="https://stackoverflow.com/a/4556267/286260">This answer</a> answers to a very similar question.</p>
  
  <p>Another note: This question is not about tomcat context.</p>