Jersey(1.19.1) - Rules of Injection
Previous sections have presented examples of annotated types, mostly annotated method parameters but also annotated fields of a class, for the injection of values onto those types.
This section presents the rules of injection of values on annotated types. Injection can be performed on fields, constructor parameters, resource/sub-resource/sub-resource locator method parameters and bean setter methods. The following presents an example of all such injection cases:
@Path("id: \d+")
public class InjectedResource {
// Injection onto field
@DefaultValue("q") @QueryParam("p")
private String p;
// Injection onto constructor parameter
public InjectedResource(@PathParam("id") int id) { ... }
// Injection onto resource method parameter
@GET
public String get(@Context UriInfo ui) { ... }
// Injection onto sub-resource resource method parameter
@Path("sub-id")
@GET
public String get(@PathParam("sub-id") String id) { ... }
// Injection onto sub-resource locator method parameter
@Path("sub-id")
public SubResource getSubResource(@PathParam("sub-id") String id) { ... }
// Injection using bean setter method
@HeaderParam("X-header")
public void setHeader(String header) { ... }
}
There are some restrictions when injecting on to resource classes with a life-cycle other than per-request. In such cases it is not possible to injected onto fields for the annotations associated with extraction of request parameters. However, it is possible to use the @Context annotation on fields, in such cases a thread local proxy will be injected.
The @FormParam annotation is special and may only be utilized on resource and sub-resource methods. This is because it extracts information from a request entity.
Jersey(1.19.1) - Rules of Injection的更多相关文章
- Jersey(1.19.1) - JSON Support
Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...
- 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> ...
- Jersey(1.19.1) - Hello World, Get started with a Web application
1. Maven Dependency <properties> <jersey.version>1.19.1</jersey.version> </prop ...
- 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) - Deploying a RESTful Web Service
JAX-RS provides a deployment agnostic abstract class Application for declaring root resource and pro ...
- Jersey(1.19.1) - Extracting Request Parameters
Parameters of a resource method may be annotated with parameter-based annotations to extract informa ...
- Jersey(1.19.1) - Sub-resources
@Path may be used on classes and such classes are referred to as root resource classes. @Path may al ...
- Jersey(1.19.1) - Building URIs
A very important aspects of REST is hyperlinks, URIs, in representations that clients can use to tra ...
- Jersey(1.19.1) - WebApplicationException and Mapping Exceptions to Responses
Previous sections have shown how to return HTTP responses and it is possible to return HTTP errors u ...
随机推荐
- POJ1328Radar Installation(贪心)
对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- [置顶] a+=1/a=+1/a-=1区别-c语言
1.解释 a+=1/a=+1/a-=1 含义 a+=1 实质等于 a += 1,也就是等于 a = a + 1: a=+1 实质等于 a = +1:[因为运算符中没有=+,很多人误以为是 a =+ 1 ...
- PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版
, '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...
- PostgreSQL的 initdb 源代码分析之二十四
继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...
- RFID与射频卡电器特性
电气特性: 容量为8K位EEPrOM: ● 分为16个扇区,每个扇区为4块,每块16个字节,以块为存取单位: ● 每个扇区有独立的一组密码及访问控制: ● 每张卡有唯一序列号,为32位: ● 具有防冲 ...
- JQuery Plugin 1 - Simple Plugin
1. How do you write a plugin in jQuery? You can extend the existing jQuery object by writing either ...
- 飘逸的python - 编码杂症之在字符串前面加u
有时候我们从其它地方接受的字符串经过艰难跋涉,它变了个样.比如收到的是'\u6253\u602a\u8005'而不是u'\u6253\u602a\u8005'. 明明肉眼看起来只需要加个u,但是怎 ...
- Linux - 打印文件夹全部文件 代码(C)
列出文件夹全部文件 代码(C) 本文地址:http://blog.csdn.net/caroline_wendy 首先配置环境,參考:http://blog.csdn.net/caroline_wen ...
- Web之真假分页
在web设计中一个无法避免的问题就是分页显示.当数据量特别大的时候,我们不可能将全部的数据都在一个页面进行显示,假设这样将严重影响到它的美观性.所以在这个时候,分页显示则成为了我们的大功臣.当然分页也 ...