更新时间:2023-12-03 14:03:40
我在使用 Jersey 时遇到了同样的问题.Java EE 标准对于 JAX-RS 声明如下:
I've been through the same issue while using Jersey. The Java EE standard for JAX-RS states the following:
3.6 注解继承
JAX-RS 注释可以用于 > 超类或已实现的方法和方法参数界面.这样的注解被对应的子类继承或实现类方法提供该方法及其参数没有任何自己的 JAX-RS 注释.注释超类优先于已实现接口上的那些.多个定义的冲突注释的优先级实现的接口是特定于实现的.
JAX-RS annotations MAY be used on the methods and method parameters of a > super-class or an implemented interface. Such annotations are inherited by a corresponding sub-class or implementation class method provided that method and its parameters do not have any JAX-RS annotations of its own. Annotations on a super-class take precedence over those on an implemented interface. The precedence over conflicting annotations defined in multiple implemented interfaces is implementation specific.
如果子类或实现方法有任何 JAX-RS 注释,则超类或接口方法上的所有注释都是忽略.
虽然 Jersey 作为参考实现对这个声明非常严格,但 Resteasy 实现更宽松,并没有我的诀窍.
While Jersey as the reference implementation is very strict with this statement, Resteasy implementation is more lenient and did the trick for me.