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. 华丽的HTML5/jQuery动画和应用 前端必备

    在网页应用中,我们经常会使用jQuery来实现一些简单的动画效果,比如菜单下拉时的渐变特效,图片滑动时的淡入淡出效果等.现在我们将jQuery和HTML5互相结合,让HTML5/CSS3强大的页面渲染 ...

  2. hibernate get VS load

    1.  执行get方法:会立即加载对象      而执行load方法,若不适用该对象,则不会立即执行查询操作,而返回一个代理对象      get立即检索,load延迟检索  2.  load方法可能 ...

  3. C++ Maps 映射

    C++ Maps是一种关联式容器,包含“关键字/值”对 begin() 返回指向map头部的迭代器 clear() 删除所有元素 count() 返回指定元素出现的次数 empty() 如果map为空 ...

  4. ubuntu bash提示找不到文件或目录

    我在ubuntu上安装好后交叉编译器,用tab键也可以找到这个交叉编译器,但执行的时候总是提示:bash:xxx找不到文件或目录. 解决方法:安装lib32z1 命令:apt-get install ...

  5. php正则表达式总结第1弹

    介绍几个我用到的php正则表达式 1. 一篇文章的链接,我需要去掉以 /hotels/打头的链接,可用下面正则 $content = preg_replace('/<a(.*?)href=&qu ...

  6. 失败经历--在windows下安装meld

    缘起 在linux下,最早用的比较工具是vim,这是作为一个vimer的自尊(其实没有关系吧).终于有一天,在比较同一个项目的两个版本的时候,比较了两三个文件后,看着vim里面花花绿绿的颜色,实在是受 ...

  7. XAML 概述一

    XAML的全称是Extensible Application Markup Language,就是我们所说的可扩展应用程序标记语言.XAML可以应用到许多不同领域,但主要用于构建用户界面. XAML是 ...

  8. GGS: Sybase to Oracle

    Step 1: Start the GGSCI on Source and Target Source Target Oracle GoldenGate Command Interpreter for ...

  9. PHP中::、->、self、$this操作符的区别

    在访问PHP类中的成员变量或方法时,如果被引用的变量或者方法被声明成const(定义常量)或者static(声明静态),那么就必须使用操作符::,反之如果被引用的变量或者方法没有被声明成const或者 ...

  10. Css compatibility

    http://meiert.com/en/indices/css-properties/ http://www.standardista.com/css3/css3-selector-browser- ...