What does Provider in JAX-RS mean?

后端 未结 3 1103
情深已故
情深已故 2020-11-30 17:38

Could anyone explain to me what a JAX-RS Provider is and what ‘@Provider’ annotation does? I have been reading documentation but I cant get it.
If there are resource cla

3条回答
  •  悲哀的现实
    2020-11-30 18:20

    To do certain activities such as Filtering-Request/Response, Exception Handling, the JAX-RS has its own default implementation logic. However, it allows users to provider thier own implementation as well.

    To provide our own implementation we need to implement the appropriate classes by specifying them with @Provider annotation.

    JAX-RS will do a round of scanning to find the existance of any such user-defined implementation by seaching for @Provider annotation.

    For example:

    ...
    @Provider
    public class AppExceptionMapper implements ExceptionMapper {
    ...
    
    ...
    @Provider
    @PreMatching
    public class RESTRequestResponseFilter implements ContainerRequestFilter, ContainerResponseFilter {
    ...
    

提交回复
热议问题