1
我想创建自己的自定义验证错误消息。我搜索了这么多的论坛,但我不知道我哪里错了。MyCustomExceptionMapper未调用 - 自定义验证错误消息 - 泽西岛验证
@Provider
public class ConstraintViolationExceptionMapper implements ExceptionMapper<ValidationException>{
private String field;
private String code;
private String message;
public ConstraintViolationExceptionMapper(){
}
@Override
public Response toResponse(ValidationException e) {
message = e.getMessage();
InvalidRespose invalidRespose = new InvalidRespose(code, message, field);
return Response.status(400).entity(invalidRespose).type(MediaType.APPLICATION_JSON).build();
}
}
资源类
@POST
@Path("/increment")
@Consumes(MediaType.APPLICATION_JSON)
@Timed
public Response greetings(@Valid @NotNull @Pattern(regexp = "^[1-9]\\d*$", message = "Should be a positive Number") @PathParam("id") String account_id){
...
...
}
我已经注册了我的ExceptionMapper在我Applicationclass作为
environment.jersey().register(new ConstraintViolationExceptionMapper());
我不知道我要去的地方错了。