JAX-RS/Jersey中的资源类和提供者类之间有什么区别? [英] What is the difference between Resource Class and Provider class in JAX-RS/Jersey?

查看:74
本文介绍了JAX-RS/Jersey中的资源类和提供者类之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jersey/JAX-RS中,我听到了资源类"和提供者"这两个术语.我不清楚这两者之间有什么区别.有人可以提供一些适当的解释吗?

In Jersey/JAX-RS I hear the terms "Resource classes" and "Providers". I am not clear on what the difference between these two are. Can someone please provide some proper explanation?

推荐答案

Resource classes are your classes annotated with @Path and providers are any other classes that we can extend/implement that allow us to tap into/extend the JAX-RS framework, i.e.

  • ContainerRequestFilter
  • ContainerResponseFilter
  • MessageBodyReader
  • MessageBodyWriter
  • WriterInterceptor
  • ReaderInterceptor
  • ContextResolver
  • ExceptionMapper
  • ClientRequestFilter
  • ClientResponseFilter
  • ContainerRequestFilter
  • ContainerResponseFilter
  • MessageBodyReader
  • MessageBodyWriter
  • WriterInterceptor
  • ReaderInterceptor
  • ContextResolver
  • ExceptionMapper
  • ClientRequestFilter
  • ClientResponseFilter

除了客户端过滤器外,所有这些提供程序类都可以用@Provider注释,并在启用扫描后自动在服务器端注册.

Aside from the client filters, all of these provider classes can be annotated with @Provider and automatically register on the server side when scanning is enabled.

您可能经常会听到诸如您正在使用哪个JSON提供程序?"之类的问题.如

You might often hear questions like "What JSON provider are you using?" This refers to the MessageBodyReader or MessageBodyWriter, which is a type of provider, or more precisely an "Entity Provider", as mentioned in the docs. This is really the only provider type with its own prefix type. All others are just generalized as being a "Provider".

可能会有更多的提供程序类型,但是这些我现在想不起来.

There may be more provider types, but these are all I can think of off the top of my head right now.

这篇关于JAX-RS/Jersey中的资源类和提供者类之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆