so I am creating a User API and I'm trying to call getUserByEmail() before login. My problem is that I get a Ambiguous handler methods mapped for HTTP path ERROR.
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> getUser(@PathVariable("id") int id) {
System.out.println("Fetching User with id " + id);
User user = userService.findById(id);
if (user == null) {
System.out.println("User with id " + id + " not found");
return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
}
@RequestMapping(value = "/user/{email}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> getUserByEmail(@PathVariable("email") String email) {
System.out.println("Fetching User with email " + email);
User user = userService.findByEmail(email);
if (user == null) {
System.out.println("User with email " + email + " not found");
return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
}
Here is the error response I get:
{"timestamp":1460226184275,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalStateException","message":"Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/user/fr': {public org .springframework.http.ResponseEntity com.ffa.controllers.UserController.getUser(int), public org.springframework .http.ResponseEntity com.ffa.controllers.UserController.getUserByEmail(java.lang.String)}","path":"/user /fr"}
I know my problem has something to do with me having a GET that is the same but with different parameter types. Any help would be greatly appreciated!