Search code examples
javamysqldatabasespring-bootget

spring-boot: can i fix next error in spring-boot 2?


i have this code:

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(method = RequestMethod.GET,value = "/login")
    public ResponseEntity<User> getUser(@RequestBody User user) {

        if (userService.findByEmailAndPassword(user.getUsername(), user.getPassword()) !=null) {
            return new ResponseEntity<User>(user, HttpStatus.OK);
        }
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);

   }
}

and when i try to use ths method in swegger show me the next error: and i dont know how to fix this error, and i need help! this method is used for a login android-app, but its not ready to be used

{
  "timestamp": 1543509200623,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.http.converter.HttpMessageNotReadableException",
  "message": "Required request body is missing: public org.springframework.http.ResponseEntity<edu.utcluj.track.user.User> edu.utcluj.track.user.UserController.getUser(edu.utcluj.track.user.User)",
  "path": "/user/login"
}

Solution

  • It looks to me like you need to send the User object as the request body in a POST request. It's not finding the request body because you're using a GET request that's not sending a request body.