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的更多相关文章

  1. Jersey(1.19.1) - JSON Support

    Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...

  2. 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> ...

  3. Jersey(1.19.1) - Hello World, Get started with a Web application

    1. Maven Dependency <properties> <jersey.version>1.19.1</jersey.version> </prop ...

  4. Jersey(1.19.1) - Root Resource Classes

    Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...

  5. Jersey(1.19.1) - Deploying a RESTful Web Service

    JAX-RS provides a deployment agnostic abstract class Application for declaring root resource and pro ...

  6. Jersey(1.19.1) - Extracting Request Parameters

    Parameters of a resource method may be annotated with parameter-based annotations to extract informa ...

  7. 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 ...

  8. Jersey(1.19.1) - Building URIs

    A very important aspects of REST is hyperlinks, URIs, in representations that clients can use to tra ...

  9. 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 ...

随机推荐

  1. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  2. HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)

    题意:略. 析:首先是假设前n-2个已经放好了,那么放第 n 个时,先考虑一下第 n-1 放的是什么,那么有两种情况. 如果n-1放的是和第1个一样的,那么第 n 个就可以在n-2的基础上放2个,也就 ...

  3. 学习php 韩顺平 数据类型 三元运算,字符串运算类型运算

    数据类型 整型:int 4个字节长度 1个字节8个bit 所以最大的整型数值是2的31次方 第一位是的0,1 表示正负,0表示正数,1表示负数 小数(float)分 精度计算  从左边开始算第一个不为 ...

  4. heidsoft logo

  5. 美国VPS推荐1GB 50GB可以win

    今天向大家推荐一款vps,1GB内存 50G硬盘 8M带宽 不限制流量,并且可以安装windows,年付才290元. 购买链接:http://www.jinbaoidc.com/page.aspx?c ...

  6. Android——设计原则(Design Principles)

    Enchant Me Delight me in surprising ways(动画.音效...) Real objects are more fun than buttons and menus( ...

  7. PI-webservice05-SAP调用外部webservice

    在用webservice进行数据传输的过程中,SAP系统与.net开发的信息系统之间的数据调用.如何用SAP调用外部的.net系统发布的webservice程序来获取外部的数据,详情请见下文: 1,创 ...

  8. 图形化OpenGL调试器 BuGLe [转]

    BuGLe 结合图形化的OpenGL调试与选择的过滤器上的OpenGL命令流.调试器可以查看状态.纹理.framebuffers ,着色器,而过滤器允许日志,错误检查,自由相机控制,视频捕捉等. 主页 ...

  9. 检测Insert、Capslock、NumLock、ScrollLock状态键的状态

    unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...

  10. iOS开发——数据解析Swift篇&简单json数据处理

    简单json数据处理 //loadWeather var url = NSURL(string: "http://www.weather.com.cn/adat/sk/101240701.h ...