Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Jersey 应用程序,如果发生任何类型的异常,我想阻止客户端看到任何类型的堆栈跟踪。如何在不更改任何现有代码的情况下做到这一点?
您可以按如下方式注册异常映射器来处理所有异常并自定义 HTTP 响应:
@Provider public class MyExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Exception> { @Override public Response toResponse(Exception ex) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }