I have a custom exception class annotated to return a given HttpStatus:
@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason=\"Invalid parameter\")
You can use HttpServletResponse's sendError function to achieve that.
Here is an example of how to use it:
@RequestMapping(value = "some/url", method = RequestMethod.POST)
public void doAction(final HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.BAD_REQUEST.value(), "custom error message");
}