I use Spring Boot. I created theses two method:
@RequestMapping(value = "/user/{userId}", method = RequestMethod.GET) public UserAppDto getNameByUserId(@PathVariable("userId") Long userId) { return userService.getByUserId(userId); } @RequestMapping(value = "/user/{username}", method = RequestMethod.GET) public UserAppDto getNameByUsername(@PathVariable("username") String username) { return userService.getNameByUsername(username); } When i try to log in the web application, i get:
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/rest/user/bsmith': {public com.zenar.dto.UserAppDto com.zenar.controller.UserController.getNameByUsername(java.lang.String), public com.zenar.dto.UserAppDto com.zenar.controller.UserController.getNameByUserId(java.lang.Long)}
Seem like, it's not able to do difference on the data type.
So need to modify URL? Any fix in the latest release?
123is not a username (who says someone doesn't create a user with that as a username). You might be able to get it to work by including a regex to limit somethings but I wouldn't count on it.