wildfly21–如何定制bean验证异常的返回

bhmjp9jg  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(318)

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

@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) {
        ...
    }
}

但所发生的只是resteasyviolationexceptionapper的默认行为。我的自定义异常apper从未被调用。我不知道还能尝试什么。

tv6aics1

tv6aics11#

我不知道为什么我第一次试的时候它不起作用,但是这个很管用

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

相关问题