title: Spring MVC Annotated Controller Interface with @PathVariable
body: <p>Is there any reason not to map Controllers as interfaces?</p>
  
  <p>In all the examples and questions I see surrounding controllers, all are concrete classes. Is there a reason for this? I would like to separate the request mappings from the implementation. I hit a wall though when I tried to get a <code>@PathVariable</code> as a parameter in my concrete class.</p>
  
  <p>My Controller interface looks like this:</p>
  
  <pre><code>@Controller
  @RequestMapping("/services/goal/")
  public interface GoalService {
  
      @RequestMapping("options/")
      @ResponseBody
      Map&lt;String, Long&gt; getGoals();
  
      @RequestMapping(value = "{id}/", method = RequestMethod.DELETE)
      @ResponseBody
      void removeGoal(@PathVariable String id);
  
  }
  </code></pre>
  
  <p>And the implementing class:</p>
  
  <pre><code>@Component
  public class GoalServiceImpl implements GoalService {
  
      /* init code */
  
      public Map&lt;String, Long&gt; getGoals() {
          /* method code */
          return map;
      }
  
      public void removeGoal(String id) {
          Goal goal = goalDao.findByPrimaryKey(Long.parseLong(id));
          goalDao.remove(goal);
      }
  
  }
  </code></pre>
  
  <p>The <code>getGoals()</code> method works great; the <code>removeGoal(String id)</code> throws an exception</p>
  
  <pre><code>ExceptionHandlerExceptionResolver - Resolving exception from handler [public void
      todo.webapp.controllers.services.GoalServiceImpl.removeGoal(java.lang.String)]: 
      org.springframework.web.bind.MissingServletRequestParameterException: Required 
      String parameter 'id' is not present
  </code></pre>
  
  <p>If I add the <code>@PathVariable</code> annotation to the concrete class everything works as expected, but why should i have to re-declare this in the concrete class? Shouldn't it be handled by whatever has the <code>@Controller</code> annotation?</p>