Spring Framework
  1. Spring Framework
  2. SPR-9253

Controller extension doesn't allow extending REST Urls

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor 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".

        Issue Links

          Activity

          Hide
          Rossen Stoyanchev added a comment -

          Fix code formatting.

          Show
          Rossen Stoyanchev added a comment - Fix code formatting.
          Hide
          Rossen Stoyanchev added a comment -

          It should work that way. Which version and which @MVC classes are you using? May I suggest putting together a quick sample on the issues repo that we can work off of?

          Show
          Rossen Stoyanchev added a comment - It should work that way. Which version and which @MVC classes are you using? May I suggest putting together a quick sample on the issues repo that we can work off of?
          Hide
          Rossen Stoyanchev added a comment -

          Duplicate of SPR-9366.

          Show
          Rossen Stoyanchev added a comment - Duplicate of SPR-9366 .

            People

            • Assignee:
              Rossen Stoyanchev
              Reporter:
              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:
                1 year, 48 weeks, 5 days ago