Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9253

Controller extension doesn't allow extending REST Urls

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      This is best explained by an example

      @Controller 
      @RequestMapping("/base")
      public class MyController{
      
      	@RequestMapping(method = RequestMethod.GET, value = "/start.html")
      	public String doSomething(
      			ModelMap model,
      			NativeWebRequest request) throws Exception {
      [...]
      
      	@RequestMapping(method = RequestMethod.POST, value = "/start.html")
      	public String doSomething(
      			@ModelAttribute("vo") MyVO vo,
      			BindingResult result,
      			ModelMap model,
      			NativeWebRequest request) throws Exception {
      [...]
      }
      
      @Controller 
      @RequestMapping("/base/extend")
      public class MyExtendedController extends MyController{
      
      	@RequestMapping(method = RequestMethod.GET, value = "/start.html")
      	public String doSomething(
      			ModelMap model,
      			NativeWebRequest request) throws Exception {
      [...]
      
      	@RequestMapping(method = RequestMethod.POST, value = "/start.html")
      	public String doSomething(
      			@ModelAttribute("vo") MyVO vo,
      			BindingResult result,
      			ModelMap model,
      			NativeWebRequest request) throws Exception {
      [...]
      }
      

      This will make Spring think start.html occurs twice in the same controller and throw and IllegalStateException.

      The reason to want to extend controllers is to be able to use common methods.

      AFAIK, the only way to extend controllers is to use RequestMapping at the Controller level. It is not possible to just use RequestMappings at the method level in this scenario. I consider it very inelegant, especially in the context of REST, that the urlpath has to be unique at an endpoint level ("/start.html"). It should be unique taken into account the entire requestmapping ("/base/start.html", "/base/extend/start.html".

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rstoya05-aop Rossen Stoyanchev
                Reporter:
                mschipperheyn marc schipperheyn
                Last updater:
                Trevor Marshall
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  6 years, 5 weeks, 4 days ago