Spring mvc Ambiguous mapping found. Cannot map controller bean method

For me adding "params" attribute in @RequestMapping worked as shown

  @ResponseBody
  @RequestMapping(method = RequestMethod.GET, params = {"id"})
  public User getUserById(final @RequestParam(name="id", required = true) String Id)
    throws InvalidArgumentException {

    return userService.getUserById(UUID.fromString(Id));
  }

  /**
   * REST service endpoint.
   * @param name Unique name for the user in the system.
   * @return Object of type {@link User} if exists otherwise null.
   */
  @ResponseBody
  @RequestMapping(method = RequestMethod.GET, params = {"name"})
  public User getUserByName(final @RequestParam(name="name", required = true) String name)
    throws InvalidArgumentException {

    return userService.getUserByName(name);
  }

However adding both the parameters at a time in query string will give 500 error with message :

Ambiguous handler methods mapped for HTTP path

In that case you can have another controller method taking both params and but only uses one of them which I feel is not necessary.


If the issue is about ambigious method, probably the @RequestMapping should be the issue. Change from @RequestMapping(name =...) to @RequestMapping(value =...)

@RequestMapping(name = "xxx.htm", method = RequestMethod.GET)

to

@RequestMapping(value = "xxx.htm", method = RequestMethod.GET)

You should write

@Controller("/review")
public class ReviewController {

and

@Controller("/book")
public class BookController {

because in your code you have the two methods without an explicit/unique path for mapping(eg. if we have a call /edit/1 , this is impossible clearly to determine a controller's method from your editBook BookController or ReviewController editReview)