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

Overloaded @PathVariable based handler methods fail with ambiguity when URL mapping is specified in XML

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 3.0.3
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None

      Description

      If the Controller URL-Mapping is configured in a urlMapping bean (SimpleUrlHandlerMapping), as opposed to directly in the Controller itself, overloaded controller methods become ambiguous.

      For example, given the following URIs (or see forum post):

      /people/{id}.html
      /people/{id}/{type}.html

      That are mapped to a single controller with the following overloaded controller methods:

      @RequestMapping(method = RequestMethod.GET)
      public ModelAndView viewProfile(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response);
       
      @RequestMapping(method = RequestMethod.GET)
      public ModelAndView viewProfile(@PathVariable("id") String id, @PathVariable("type") String type, HttpServletRequest request, HttpServletResponse response);

      Accessing either URL will fire an exception about these two methods being ambiguous.

      However, if the URI mapping is specified in the controller methods' RequestMapping annotation, everything works as expected.

      In this case, method #1 above is simply calling method #2 with the type argument set to null. (A common idiom.)

        Issue Links

          Activity

          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          I'm afraid this is a known limitation at this point. @PathVariable is only really designed for working with local @RequestMapping paths, in particular when multiple matches are being found, with a best match to be chosen.

          We'll revisit this for Spring 3.1 in combination with externalized URL mappings.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - I'm afraid this is a known limitation at this point. @PathVariable is only really designed for working with local @RequestMapping paths, in particular when multiple matches are being found, with a best match to be chosen. We'll revisit this for Spring 3.1 in combination with externalized URL mappings. Juergen
          Hide
          digerata Mike Wille added a comment -

          Okay, thanks for the update! For us, externalized URL is the only way to go. Our biggest project has almost 300 urls mapped. Moving them into controller annotations just isn't an option.

          Show
          digerata Mike Wille added a comment - Okay, thanks for the update! For us, externalized URL is the only way to go. Our biggest project has almost 300 urls mapped. Moving them into controller annotations just isn't an option.
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          The new RequestMappingHandlerAdapter (see SPR-8214) expects a HandlerMethod and cannot be used in combination with SimpleUrlHandlerMapping. Given that this adapter takes the place of the existing AnnotationMethodHandlerAdapter, it is unlikely we will address this issue as described.

          A more likely outcome would be to provide a RequestMappingHandlerMapping variant that prepares request mappings from external configuration rather that from annotations.

          For this reason I am linking in SPR-5757.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - The new RequestMappingHandlerAdapter (see SPR-8214 ) expects a HandlerMethod and cannot be used in combination with SimpleUrlHandlerMapping . Given that this adapter takes the place of the existing AnnotationMethodHandlerAdapter , it is unlikely we will address this issue as described. A more likely outcome would be to provide a RequestMappingHandlerMapping variant that prepares request mappings from external configuration rather that from annotations. For this reason I am linking in SPR-5757 .
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          This issue is effectively superseded by SPR-5757. Since DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter are both deprecated in 3.2 while their successors RequestMappingHandlerMapping/Adapter only support annotation based mappings, effectively SPR-5757 is the only way to address this request.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - This issue is effectively superseded by SPR-5757 . Since DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter are both deprecated in 3.2 while their successors RequestMappingHandlerMapping/Adapter only support annotation based mappings, effectively SPR-5757 is the only way to address this request.

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              digerata Mike Wille
              Last updater:
              Rossen Stoyanchev
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 45 weeks ago