Jersey 中的多个 ExceptionMappers

Multiple ExceptionMappers in Jersey

假设我有两个 ExceptionMappers:

public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplicationException>
( class WebApplicationException extends RuntimeException )
public class GenericExceptionMapper implements ExceptionMapper<Throwable>

如果抛出WebApplicationException或WebApplicationException的子异常,哪个映射器会处理它们?有人可以解释一下吗?

谢谢

这在关于 ExceptionMappers 的 JAX-RS 规范中有说明

When choosing an exception mapping provider to map an exception, an implementation MUST use the provider whose generic type is the nearest superclass of the exception.

基本上,它是说您的 Throwable 映射器将具有最低优先级,因为它是距任何异常类型最远的超类型。任何 WebApplicationException 或其子类将始终使用 WebApplicationException 映射器。