【发布时间】:2015-01-02 15:51:00
【问题描述】:
我正在尝试使用 ExceptionMapper 管理我的所有异常,正如我在多个文档和示例中看到的那样。但是,至少在我的情况下,它似乎不起作用。
我在 OSGI 环境中,使用 Felix Witheboard 模式和 Amdatu Wink,所以我没有 web.xml,一切都应该由自己管理。 我尝试将我的 ExceptionMapper 注册为服务,就像我对我的 Web 服务所做的那样,但没有结果。
@Component(immediate=true, provide={Object.class})
@Provider
public class SessionTimeoutExeptionHandler implements ExceptionMapper<SessionTimeoutException>{
public Response toResponse(SessionTimeoutException arg0) {
Response toReturn = Response.status(Status.FORBIDDEN)
.entity("session_timeout")
.build();
return toReturn;
};
}
不要关注响应本身,我只是在玩。
我的代码从未被调用,我应该如何设置该提供程序?
【问题讨论】: