0

我尝试以多种方式注册自定义异常映射器:

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ConstraintViolationException> {
    @Override
    public Response toResponse(ConstraintViolationException exception) {
        ...
    }
}

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ResteasyViolationException> {
    @Override
    public Response toResponse(ResteasyViolationException exception) {
        ...
    }
}

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ValidationException> {
    @Override
    public Response toResponse(ValidationException exception) {
        ...
    }
}

但发生的一切都是 ResteasyViolationExceptionMapper 的默认行为。我的自定义 ExceptionMapper 永远不会被调用。我不知道还能尝试什么。

4

1 回答 1

0

我不知道为什么我第一次尝试它时它不起作用,但这有效

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ValidationException> {
    @Override
    public Response toResponse(ValidationException exception) {
        ...
    }
}
于 2020-12-23T07:52:47.820 回答