我正在使用 Jersey Guice,需要配置自定义ExceptionMapper
我的模块如下所示:
public final class MyJerseyModule extends JerseyServletModule
{
@Override
protected void configureServlets()
{
...
filter("/*").through(GuiceContainer.class);
...
}
}
这是我的ExceptionMapper
:
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
public class MyExceptionMapper implements ExceptionMapper<MyException>
{
@Override
public Response toResponse(final MyException exception)
{
return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
}
}