支持的接口

  • Application
  • Configuration
  • Providers
  • MessageBodyReader
  • MessageBodyReader
  • MessageBodyWriter
  • ContextResolver
  • ExceptionMapper
  • Feature
  • DynamicFeature
  • ContainerRequestFilter
  • ContainerResponseFilter
  • ReaderInterceptor
  • WriterInterceptor
  • ParamConverterProvider
  • @Priority
  • @ConstrainedTo
  • @PreMatching
  • @NameBinding

使用方式

使用时将实现上述接口的实现类直接注入Spring容器并加上指定注解(如果是Controller方法需要加上@Path,其他的扩展加上@Provider)即可生效。

eg.

1.自定义Application@ApplicationPath("/abc")为可选项
@ApplicationPath("/abc")
@Component
public class ApplicationImpl extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        return Collections.singleton(HelloWorldResource.class);
    }

}
2.自定义Provider
@Component
@Provider
public class RequestFilterDemo implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext context) {
        context.getHeaders().add("name", "value");
    }
    
}
3.自定义Controller
@Component
@Path("/simple")
public class HelloWorldController {

    @GET
    public String index() {
        return "Hello JAX-RS3.0";
    }

}