[英]Jersey Exception Mapper not handling Exceptions in Resource Constructor
I have the following Exception Mapper for my jersey-server: 我的球衣服务器具有以下异常映射器:
@Provider
public class ExceptionResponseMapper implements ExceptionMapper<Throwable> {
Logger logger = Logger.getLogger(ExceptionResponseMapper.class);
@Override
public Response toResponse(Throwable e) {
log.error(e);
Response response = Response.status(500)
.entity(e)
.build();
return response;
}
}
I register this provider with manually with config.register(ExceptionResponseMapper.class);
我使用config.register(ExceptionResponseMapper.class);
手动注册了该提供程序config.register(ExceptionResponseMapper.class);
The Exception Mapper works perfectly fine for the exceptions thrown in my REST resource classes, except for exceptions in the constructor. 对于构造函数中的异常,我的REST资源类中引发的异常非常适合异常映射器。
Eg. 例如。
@Path("/MyResource")
public class MyResource {
public MyResource() {
throw new RuntimeException();
}
}
will not invoke the Exception Mapper. 将不会调用异常映射器。 How can I handle this case of exceptions? 我该如何处理这种例外情况?
当您通过Spring或CDI创建资源时,我的猜测是Jersey Context还没有准备好(如果您使用的是DI框架)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.