toResponse in jersey ExceptionMapper 不會被调用
所以我正在构建一个Web应用程序,我们正在使用JPA和Jersey来使用/生成JSON数据。
我有一个自定义的“EntityException”以及一个自定义的“EntityExceptionMapper”
这是映射器:
@Provider
public class EntityExceptionMapper implements ExceptionMapper<EntityException> {
public EntityExceptionMapper() {
System.out.println("Mapper created");
}
@Override
public Response toResponse(EntityException e) {
System.out.println("This doesnt print!");
return Response.serverError().build();
}
}
我的例外:
public class EntityException extends Exception implements Serializable{
public EntityException(String message) {
super(message);
System.out.println("This prints...");
}
}
我从REST调用中调用它:
@POST
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public String test() throws EntityException{
throw new EntityException("This needs to be send as response!!");
//return "test";
}
我的问题是,当抛出上述异常时,我进入构造函数(打印:“此打印...”)编辑:我也得到:“映射器创建!
但是我的响应是空的,并且我没有从我的toResponse方法中获得系统。这与球衣网站上的示例非常相似:
https://jersey.java.net/nonav/documentation/1.12/jax-rs.html#d4e435
我错过了什么??