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> ...
随机推荐
- 配置FTP服务
配置FTP服务 1.安装FTP服务器(默认已安装) 服 务:vsftpd 位 置:光盘1 软 件:vftpd-2.0.1-5.i386.rpm 配 置:/etc/vsftpd/vsftpd.conf ...
- SQL server基本操作(一)
--1.create database CREATE DATABASE MyDB GO --2.use database USE MyDB GO --3.create table CREATE T ...
- nyoj_t218(Dinner)
描述 Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he dec ...
- javascript给不能修改的函数增加额外处理的方法
不知道是否可行,但姑且google之. 查看到相关的stack overflow(堆栈溢出)帖子:http://stackoverflow.com/questions/1659219/add-to-a ...
- C语言求两个函数中的较大者的MAX函数
//求两个函数中的较大者的MAX函数 #include <stdio.h> int main(int argc, const char * argv[]) { printf("i ...
- 实验三——SDRAM
一.运行环境 开发板:jz2440 系统: ubuntu12.04 编译器:arm-linux-gcc 二.特殊寄存器 sdram的操作无需按照时序图来设置,只要设置好相关的13个寄存器,arm处理 ...
- xml_editor
概要 该工程是用来操作xml, 目的是为了在程序中操作xml中各类节点更加简单, 下面按照 工程简介, 库内部实现, 库接口使用, xml工具使用, xpath简介 几个部分来介绍该c++库. 工程简 ...
- git 的使用(4)-git暂缓区工作区原理和修改删除等命令
文章转载自:http://blog.csdn.net/think2me/article/details/39056379 博主说未经本人允许,不得转载,那就不贴了,拷贝关键部分作备忘 1. 暂存区是G ...
- git 合并本地代码到分支
本地代码合并到dev分支 在local分支提交git add .git commit -m "playbuy" 切换到dev分支git checkout devgit pull合并 ...
- Less 导入命令 @import
在这个less文件上想导入另一个less文件, 连在同级的文件里直接可用文件名 @import url('css.less')或@import rul(css) 连下级的文件 @import url( ...



