JAX-RS @Provider注解用来做什么

被@Provider注解标注的class一定都要实现一个JAX-RS规范的接口,JAX-RS runtime(比如tomcat等)会有一个对于这些接口的一个基本的实现,我们自己实现接口相当于替换了容器实现的接口,实现一些定制化的功能

Providers are a simply a way of extending and customizing the JAX-RS runtime. You can think of them as plugins that (potentially) alter the behavior of the runtime, in order to accomplish a set of (program defined) goals.

Providers are not the same as resources classes, they exist, conceptually, at a level in-between resources classes and the JAX-RS implementation. If it helps, you can think of them in the same light as device drivers (existing between user and kernel space). This is a broad generalization.

There are three classes of providers defined by the current JAX-RS specification. The commonality between them is that all providers must be identified by the @Provider annotation and follow certain rules for constructor declaration. Apart from that, different provider types may have additional annotations, and will implement different interfaces.


Entity Providers

These providers control the mapping of data representations (like XML, JSON, CSV) to their Java object equivalents.

Context Providers

These providers control the context that resources can access via @Context annotations.

Exception Providers

These providers control the mapping of Java exceptions to a JAX-RS Response instance.


Your runtime will come with a number of predefined providers that will be responsible for implementing a base level of functionality (e.g for mapping to and from XML, translating the most common exceptions etc etc). You can also create your own providers as needed.

The JAX-RS specification is a good reference for reading up on these different provider types and what they do (see Chapter 4).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值