The exception that you pass as the argument to setErrorResult can be annotated with @ResponseStatus . For example, create your own exception class:
@ResponseStatus(HttpStatus.NOT_FOUND) class NotFoundException extends RuntimeException {
Then in your code use it with the constructor you created, for example:
deferredResult.setErrorResult(new NotFoundException(reason, cause));
source share