简体   繁体   English

JAX-RS / Jersey:如何“继承” @Provider字段?

[英]JAX-RS/Jersey: How can I “inherit” @Provider fields?

In JAX-RS one can define @Provider -annotated fields or inner-classes (such as for MessageBodyReader or ExceptionMapper ). 在JAX-RS中,可以定义@Provider字段或内部类(例如MessageBodyReaderExceptionMapper )。

Sadly, I can't inherit this logic from a super class. 可悲的是,我不能从超类继承这种逻辑。 (When I do, JAX-RS simply ignores them.) (当我这样做时,JAX-RS只会忽略它们。)

I have several JAX-RS resource classes, so I don't want to copy+paste these providers in each of them. 我有几个JAX-RS资源类,所以我不想在每个提供者中复制并粘贴这些提供者。

So, how can I define providers in a project-"global" sense? 那么,如何从项目的“全局”意义上定义提供者?

in your WEB-INF/web.xml 在您的WEB-INF / web.xml中

<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>
your.package.one;your.package.two
</param-value>
</init-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Jersey JAX-RS实现中编组空字段? - How to marshall null fields in Jersey JAX-RS implementation? JERSEY和JAX-RS - JERSEY and JAX-RS 如何使用Jersey JAX-RS返回结果集? - How do I return a resultset using Jersey JAX-RS? 如何通过JAX-RS(Jersey)从客户端获取带有JSON数据和文件上传的请求? - How can I get request from the client with JSON data and fileupload via JAX-RS(Jersey)? 如何在JAX-RS(Jersey)中读取cookie - How to read a cookie in JAX-RS (Jersey) 球衣(Jax-RS)和EL - Jersey (Jax-RS) & EL Nginx 代理:如何配置 nginx 以便 Jersey 2 (JAX-RS 2) 仍然可以正确地与其中的其他 URL 部分交互? - Nginx proxy: How do I configure nginx so that Jersey 2 (JAX-RS 2) still can interact with additional URL parts in it properly? 如何通过JAX-RS(Jersey)使用$ resource从AngularJS客户端使用JSON数据和文件上传向服务器发送请求? - How can I send request to the server with JSON data and fileupload from AngularJS client using $resource via JAX-RS(Jersey)? 如何使用JAX-RS(Jersey)编写服务器端Java代码以将任何类型的文件作为流返回? - How can I write a server side java code to return any kind of file as stream using JAX-RS(Jersey)? 使用JAX-RS混淆了JAX-RS和Jersey - Confusion with JAX-RS and Jersey with JAX-RS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM