title: Spring MVC controller inheritance and routing
body: <p>In my Spring MVC webapp I have a generic RESTful controller for CRUD operations. And each concrete controller had to declare only a <code>@RequestMapping</code>, for example <code>/foo</code>. Generic controller handled all request to <code>/foo</code> and <code>/foo/{id}</code>. </p>
  
  <p>But now I need to write a bit more complex CRUD controller which will get additional request params or path variables, e.g <code>/foo/{date}</code> and <code>/foo/{id}/{date}</code>. So I extend my generic CRUD controller and write overloaded <code>fetch(id, date)</code> method which will deal with both <code>{id}</code> and <code>{date}</code>. That is not a problem.</p>
  
  <p>But I also need to 'disable'  <code>fetch(id)</code> implementation derived from base class (resource mustn't be available at <code>/foo/{id}</code> anymore, only at <code>/foo/{id}/{date}</code>). The only idea I came up with is to override this method in my concrete controller, to map it on a fake uri and return <code>null</code>. But this looks like rather ugly dirty hack because we expose some fake resource uri, instead of disabling it. May be there is a better practice?</p>
  
  <p>Any ideas?</p>
  
  <pre><code>//My generic CRUD controller
  public abstract class AbstractCRUDControllerBean&lt;E, PK extends Serializable&gt; implements AbstractCRUDController&lt;E, PK&gt; {
  
    @RequestMapping(method=RequestMethod.GET)
    public @ResponseBody ResponseEntity&lt;E[]&gt; fetchAll() { ... }
  
    @RequestMapping(value="/{id}", method=RequestMethod.GET)
    public @ResponseBody ResponseEntity&lt;E&gt; fetch(@PathVariable("id") PK id) { ... }
  
    @RequestMapping(method=RequestMethod.POST)
    public @ResponseBody ResponseEntity&lt;E&gt; add(@RequestBody E entity) { ... }
  
    @RequestMapping(value="/{id}", method=RequestMethod.PUT)
    public @ResponseBody ResponseEntity&lt;E&gt; update(@PathVariable("id") PK id, @RequestBody E entity) { ... }
  
    @RequestMapping(value="/{id}", method=RequestMethod.DELETE)
    public @ResponseBody ResponseEntity&lt;E&gt; remove(@PathVariable("id") PK id) { .. }
  } 
  </code></pre>
  
  <p>.</p>
  
  <pre><code>//Concrete controller, working with Foo entities
  @Controller
  @RequestMapping("/foo")
  public class FooControllerImpl extends
          AbstractCRUDControllerBean&lt;Foo, Long&gt; implements FooController { 
  
    //ugly overriding parent's method
    @RequestMapping(value="/null",method=RequestMethod.GET)
    public @ResponseBody ResponseEntity&lt;Foo&gt; fetch(@PathVariable("id") PK id) { 
      return null;
    }
  
    //new fetch implementation
    @RequestMapping(value="/{id}/{date}", method=RequestMethod.GET)
    public @ResponseBody ResponseEntity&lt;Foo&gt; fetch(@PathVariable("id") PK id, @PathVariable("date") Date date) { .... }
  
  }
  </code></pre>