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> ...
随机推荐
- Cllimbing Stairs [LeetCode 70]
1- 问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe ...
- ubuntu设置关闭屏幕和锁定
见链接:http://askubuntu.com/questions/177348/how-do-i-disable-the-screensaver-lock If you want to wrap ...
- 【Qt】QSettings读写注册表、配置文件【转】
简述 一般情况下,我们在开发软件过程中,都会缓存一些信息到本地,可以使用轻量级数据库sqlite,也可以操作注册表.读写配置文件. 关于QSettings的使用前面已经介绍过了,比较详细,见“更多参考 ...
- mac OS X下git代码行统计命令
1.统计某人的代码提交量,包括增加,删除 git log --author=-- --until=-- --pretty=tformat: --numstat | awk '{ add += $1 ; ...
- JS 获取select(多选下拉)中所选值的示例代码
通过js获取select(多选下拉)中所选值,具体实现如下,有需要的朋友可以参考下,希望对大家有所帮助 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...
- composer安装yii2或者laravel报错
大概的信息就是提示让登陆github,然后就报错了 Could not fetch https://api.github.com/authorizations, enter your GitHub c ...
- hibernate数据库配置
在文件夹etc中 ## MySQL #hibernate.dialect org.hibernate.dialect.MySQLDialect #hibernate.dialect org.hiber ...
- Query execution was interrupted, max_statement_time exceeded
版本:5.6.16 群里看见一个问题,在备份的时候,报如下错误:[root@B28-19-75 bak]# mysqldump -root -p --single-transaction --mast ...
- 安装percona-toolkit提示的报错
[root@hank-yoon export]# tar -xvf percona-toolkit_2.2.15-2.tar.gz [root@hank-yoon export]# cd percon ...
- Input event驱动
Input event驱动 Linux 专门对输入设备. 键盘,鼠标,手柄,触摸屏.按键.封装一个类驱动. 主要统一与应用程序接口.这一类的设备结点都是在/dev/input/eventn( 0< ...



