0
votes

I created a RestController with a Post method. Somehow when I made post request http://localhost:8080/api/users from Postman, It threw 405 method not allowed error.

@RestController
@RequestMapping("/api")
  public class RestRegistrationController {

    @PostMapping("/users")
    public GenericResponse registerUserDTo(@Valid @RequestBody UserDto user) {

        return new GenericResponse("success");
    }

}

My request post

{
    "firstName":"Test",
    "password":"Pa$$w0rd",
    "lastName":"Test",
    "email":"[email protected]"
}
2
show what/how you posted. - M. Deinum

2 Answers

0
votes

Maybe error in Validation userDto object. Check all fiealds which coming via controller are the same as UserDto class

0
votes

If you does not define request method in the mapping the default is GET.

For POST:

@RequestMapping(value = "/end-point-url", method = RequestMethod.POST)