Root resource classes
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
@Pathannotation.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
widgetsand one of its methods implements theGETverb, then aGETonwidgetsinvokes that method. If a sub-resource specifies that its URI is{id}, then the full URI template for the sub-resource iswidgets/{id}and it will handle requests made to URIs likewidgets/12andwidgets/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
@Pathannotation.
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   | 
| 
 
  | 
 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  For more information on implementing sub-resources see Working with sub-resources.  | 
Root resource classes的更多相关文章
- Jersey(1.19.1) - Root Resource Classes
		
Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...
 - 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 ...
 - 九月 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 ...
 - The ResourceConfig instance does not contain any root resource classes
		
问题描述 当我们在使用 myeclipse 创建 Web Service Projects 项目后,运行项目然后就会出现这个问题. 解决方案 通过这个错误描述,我们项目没有找到这个资源.报错的原因在于 ...
 - RESTful WebService入门(转)
		
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lavasoft.blog.51cto.com/62575/229206 REST ...
 - Storm(2) - Log Stream Processing
		
Introduction This chapter will present an implementation recipe for an enterprise log storage and a ...
 - Table of Contents - Jersey
		
Jersey 1.19.1 Getting Started Get started with Jersey using the embedded Grizzly server Get started ...
 - RESTful WebService入门
		
RESTful WebService入门 RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状 ...
 - 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> ...
 
随机推荐
- 10款精美的web前端源码的特效
			
1.HTML5侧滑聊天面板 很酷的聊天界面 这是一款基于HTML5和SVG的侧滑聊天面板,初始化的时候聊天面板是锁定的,当你拖动白色区域时,即可解锁展开聊天面板,显示所有好友.点击面板中的好友即可切换 ...
 - <解说linux下proc文件系统>
			
proc文件系统的作用是访问系统内核信息 proc不是一个真实的文件系统,它不占系统的外存空间,只是以文件的形式为用户访问linux内核数据提供接口,因为系统内核总是动态的变化,所以我们所捕捉到的也只 ...
 - LR通过SiteScope监控mysql
			
SiteScope下载,安装 要想使用LoadRunner监测MySQL数据库的性能,LoadRunner没有提供直接监测 MySQL的功能,所以,我们需要借助sitescope监控,然后在LoadR ...
 - 匹配一级分类和二级分类 名字和url 里面有玄机
			
1:要匹配的html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
 - 51nod 1021 石头归并
			
1021 石子归并 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 N堆石子摆成一条线.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合 ...
 - 卸载CentOS 5.4自带的OpenJDK,配置新的Java环境
			
本文CentOS版本为5.4 final,使用图形界面与命令结合的操作方式,由于CentOS 5.4在默认情况下,会安装OpenOffice之类的软件,而这些软件需要Java支持,因此系统会默认安装一 ...
 - Eclipse使用ButterKnife前,需要的配置步骤
			
ButterKnife下载地址(7.0.1版本):http://files.cnblogs.com/files/zzw1994/butterknife-7.0.1.zip 官方下载地址(7.0.1版本 ...
 - 11g RAC R2 之Linux DNS 配置
			
在动手配置前,最好先了解下DNS的理论,以免犯不必要的错误.这都是被坑后的觉悟 -_-!!! Oracle 11g RAC 集群中引入了SCAN(SingleClientAccessName)的概念, ...
 - 第27章 项目8:使用XML-RPC进行文件共享
			
1.问题 创建一个简单的P2P文件共享程序. P2P文件共享程序是在不同计算机上的程序交换文件.P2P交互内,任何节点(peer)都可以是链接到其他节点.在这样一个由节点组成的虚拟网络中,是没有中央节 ...
 - C# 访问控制:public、private、protected和internal
			
平日工作时最常用的访问控制符是public和private,当看到prism里面大量使用protected的时候,觉得还是不太理解为啥. 所以就静下心来查找并理解了一下,这里记录下,以便回顾和交流. ...
 
			
		


