How to return 404 response status in Spring Boot @ResponseBody – method return type is Response?

This is very simply done by throwing org.springframework.web.server.ResponseStatusException:

throw new ResponseStatusException(
  HttpStatus.NOT_FOUND, "entity not found"
);

It’s compatible with @ResponseBody and with any return value. Requires Spring 5+

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)