title: Spring 3 simple extentionless url mappings with annotation-based mapping - impossible?
body: <p>I'm using Spring 3, and trying to set up a simple web-app using annotations to define controller mappings. This seems to be incredibly difficult without peppering all the urls with *.form or *.do</p>
  
  <p>Because part of the site needs to be password protected, these urls are all under /secure. There is a <code>&lt;security-constraint&gt;</code> in the web.xml protecting everything under that root. I want to map all the Spring controllers to /secure/app/. </p>
  
  <p>Example URLs would be:<br>
  /secure/app/landingpage<br>
  /secure/app/edit/customer/{id}<br>
  each of which I would handle with an appropriate jsp/xml/whatever.</p>
  
  <p>So, in web.xml I have this:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/secure/app/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>And in despatcher-servlet.xml I have this:</p>
  
  <pre><code> &lt;context:component-scan base-package="controller" /&gt;
  </code></pre>
  
  <p>In the Controller package I have a controller class:</p>
  
  <pre><code>package controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  import javax.servlet.http.HttpServletRequest;
  
  @Controller
  @RequestMapping("/secure/app/main")
  public class HomePageController {
      public HomePageController() { }
  
      @RequestMapping(method = RequestMethod.GET)
      public ModelAndView getPage(HttpServletRequest request)
      {
          ModelAndView mav = new ModelAndView();
          mav.setViewName("main");
          return mav;
      }
  }
  </code></pre>
  
  <p>Under /WEB-INF/jsp I have a "main.jsp", and a suitable view resolver set up to point to this. I had things working when mapping the despatcher using *.form, but can't get anything working using the above code.</p>
  
  <p>When Spring starts up it appears to map everything correctly:</p>
  
  <pre><code>13:22:36,762  INFO main annotation.DefaultAnnotationHandlerMapping:399 - Mapped URL path [/secure/app/main] onto handler [controller.HomePageController@2a8ab08f]
  </code></pre>
  
  <p>I also noticed this line, which looked suspicious:</p>
  
  <pre><code>13:25:49,578 DEBUG main servlet.DispatcherServlet:443 - No HandlerMappings found in servlet 'dispatcher': using default
  </code></pre>
  
  <p>And at run time any attempt to view /secure/app/main just returns a 404 error in Tomcat, with this log output:</p>
  
  <pre><code>13:25:53,382 DEBUG http-8080-1 servlet.DispatcherServlet:842 - DispatcherServlet with name 'dispatcher' determining Last-Modified value for [/secure/app/main]    
  13:25:53,383 DEBUG http-8080-1 servlet.DispatcherServlet:850 - No handler found in getLastModified    
  13:25:53,390 DEBUG http-8080-1 servlet.DispatcherServlet:690 - DispatcherServlet with name 'dispatcher' processing GET request for [/secure/app/main]    
  13:25:53,393  WARN http-8080-1 servlet.PageNotFound:962 - No mapping found for HTTP request with URI [/secure/app/main] in DispatcherServlet with name 'dispatcher'    
  13:25:53,393 DEBUG http-8080-1 servlet.DispatcherServlet:677 - Successfully completed request
  </code></pre>
  
  <p>So... Spring maps a URL, and then "forgets" about that mapping a second later? What is going on?</p>
  
  <p>Thanks.</p>