What is the difference between Resource Class and Provider class in JAX-RS/Jersey? [closed]

百般思念 提交于 2020-01-15 09:32:27

问题


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?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/52727796/what-is-the-difference-between-resource-class-and-provider-class-in-jax-rs-jerse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!