Overview

A root resource class is the entry point into a JAX-RS implemented RESTful Web service. It is decorated with a @Path that specifies the root URI of the resources implemented by the service. Its methods either directly implement operations on the resource or provide access to sub-resources.

Requirements

In order for a class to be a root resource class it must meet the following criteria:

  • The class must be decorated with the @Path annotation.

    The specified path is the root URI for all of the resources implemented by the service. If the root resource class specifies that its path is widgets and one of its methods implements the GET verb, then a GET on widgets invokes that method. If a sub-resource specifies that its URI is {id}, then the full URI template for the sub-resource is widgets/{id} and it will handle requests made to URIs like widgets/12 and widgets/42.

  • The class must have a public constructor for the runtime to invoke.

    The runtime must be able to provide values for all of the constructor's parameters. The constructor's parameters can include parameters decorated with the JAX-RS parameter annotations. For more information on the parameter annotations see Passing Information into Resource Classes and Methods.

  • At least one of the classes methods must either be decorated with an HTTP verb annotation or the @Path annotation.

Example

Example 2.3 shows a root resource class that provides access to a sub-resource.

Example 2.3. Root resource class

package demo.jaxrs.server;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; @Path("/customerservice/")
public class CustomerService
{
public CustomerService()
{
...
} @GET
public Customer getCustomer(@QueryParam("id") String id)
{
...
} @DELETE
public Response deleteCustomer(@QueryParam("id") String id)
{
...
} @PUT
public Response updateCustomer(Customer customer)
{
...
} @POST
public Response addCustomer(Customer customer)
{
...
} @Path("/orders/{orderId}/")
public Order getOrder(@PathParam("orderId") String orderId)
{
...
} }

The class in Example 2.3 meets all of the requirements for a root resource class.

The class is decorated with the @Path annotation. The root URI for the resources exposed by the service is customerservice.

The class has a public constructor. In this case the no argument constructor is used for simplicity.

The class implements each of the four HTTP verbs for the resource.

The class also provides access to a sub-resource through the getOrder() method. The URI for the sub-resource, as specified using the the @Path annotation, is customerservice/order/id. The sub-resource is implemented by theOrder class.

For more information on implementing sub-resources see Working with sub-resources.

Root resource classes的更多相关文章

  1. Jersey(1.19.1) - Root Resource Classes

    Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...

  2. Jersey(1.19.1) - Life-cycle of Root Resource Classes

    By default the life-cycle of root resource classes is per-request, namely that a new instance of a r ...

  3. 九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <init> 严重: The ResourceConfig instance does not contain any root resource classes.

    Tomcat启动错误:九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <i ...

  4. The ResourceConfig instance does not contain any root resource classes

    问题描述 当我们在使用 myeclipse 创建 Web Service Projects 项目后,运行项目然后就会出现这个问题. 解决方案 通过这个错误描述,我们项目没有找到这个资源.报错的原因在于 ...

  5. RESTful WebService入门(转)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lavasoft.blog.51cto.com/62575/229206 REST ...

  6. Storm(2) - Log Stream Processing

    Introduction This chapter will present an implementation recipe for an enterprise log storage and a ...

  7. Table of Contents - Jersey

    Jersey 1.19.1 Getting Started Get started with Jersey using the embedded Grizzly server Get started ...

  8. RESTful WebService入门

    RESTful WebService入门   RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状 ...

  9. Jersey(1.19.1) - Hello World, Get started with Jersey using the embedded Grizzly server

    Maven Dependencies The following Maven dependencies need to be added to the pom: <dependency> ...

随机推荐

  1. GDAL中RasterIO函数(把文件读取为一个一维数组)和ReadBlock函数(读取栅格数据块)

    CPLErr GDALRasterBand::RasterIO ( GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, ...

  2. JavaScript “完美运动框架”

    /* “完美运动框架”,所谓“完美”,就是可以实现多个参数,多个物体运动互不影响的一个运动函数move(). * 大致结构如下:运动框架 EXP: move(obj,{width:200,height ...

  3. php生成圆形图片

    http://files.cnblogs.com/files/adtuu/circle_image.zip

  4. 51nod1270 数组的最大代价(简单dp)

    ---恢复内容开始--- 1270 数组的最大代价 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 数组A包含N个 ...

  5. JavaScript 时间显示

    <span id="localtime"><span> <script type="text/javascript"> fu ...

  6. vs2010中安装ASP.NET AJAX Control Toolkit

    方法一: 第一步 下载Ajax Control Toolkit 进入网址http://ajaxcontroltoolkit.codeplex.com/ 即可下载 第二步 解压下载下来的Ajax Con ...

  7. Python开发【第一篇】Python基础之装饰器

    写代码要遵循开发封闭原则,虽然在这个原则是用的面向对象开发,但是也适用于函数式编程,简单来说,它规定已经实现的功能代码不允许被修改,但可以被扩展,即: 封闭:已实现的功能代码块开放:对扩展开发 #s2 ...

  8. ORA-00054

    系统版本: [root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 数据库版本: Oracle Database ...

  9. Vbox安装oracle-linux报错:VT-x features locked or unavailable in M

    1.安装完Vbox后,通过vbox来安装oracle-linux时报“VT-x features locked or unavailable in MSR”: 2.报错原因:CPU没有开启虚拟化支持 ...

  10. [JQuery]学习总结

    1. Jquery 选择多个class 如何精确匹配 $("div[class='class1 class2']").css({ "margin-bottom" ...