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.)

        Attachments

          Issue Links

            Activity

              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:
                  5 years, 31 weeks, 5 days ago