2013-10-23 36 views

回答

0

如果您使用Jersey 2.x,則可以使用ExceptionMapper來處理資源方法產生的所有異常(或特定情況)。

@Provider 
public class MyExceptionMapper implements ExceptionMapper<java.lang.Exception> { 
    public Response toResponse(java.lang.Exception ex) { 
     return Response.status(500) 
      .entity(ex.getMessage()) 
      .type("text/plain") 
      .build(); 
    } 
}