直接编写统一异常处理类即可:
@Provider
public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception exception) {
String msg;
if (exception instanceof XException) {
msg = "XException: " + exception.getMessage();
} else {
msg = "Exception: " + exception.getMessage();
}
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
其实相关的一些使用方式只要查询resteasy的使用姿势即可;