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 ...
随机推荐
- Linux性能监测
1.Linux性能监测:监测目的与工具介绍 看了某某教程.读了某某手册,按照要求改改某些设置.系统设定.内核参数就认为做到系统优化的想法很傻很天真:)系统优化是一项复杂.繁琐.长期的工作,优化前需要监 ...
- IPhone 设备状态、闪光灯状态
//判断闪光灯状态,修改默认的"CameraFlashOff" 按钮图片.转由 TGCameraFlash.m 控制图标切换 AVCaptureDevice *device ...
- session cookie原理及应用
一.术语session在我的经验里,session这个词被滥用的程度大概仅次于transaction,更加有趣的是transaction与session在某些语境下的含义是相同的. session,中 ...
- php 基本符号
用这么久了,竟然PHP的基本符号都没有认全,看到@号还查了半天才知道什么意思.把基本符号列表帖一下吧,需要的朋友可以参考~ 注解符号: // 单行注解 /* ...
- LFI漏洞利用总结(转载)
主要涉及到的函数include(),require().include_once(),require_once()magic_quotes_gpc().allow_url_fopen().allow_ ...
- 关于C++与Java中虚函数问题的读书笔记
之前一直用C++编程,对虚函数还是一些较为肤浅的理解.可近期由于某些原因搞了下Java,发现有些知识点不熟,于是站在先驱巨人的肩上谈谈C++与Java中虚函数问题. Java中的虚函数 以下是段别人的 ...
- 【转】C++笔试题汇总
原文:http://www.cnblogs.com/ifaithu/articles/2657663.html C#C++C多线程面试1.static有什么用途?(请至少说明两种)1)在函数体,一个被 ...
- Android版本号的识别——$(PLATFORM_VERSION)
#/******************************************************************************#*@file Android.mk#* ...
- nginx配置图片服务器
这几天研究了一下nginx配置图片服务器的相关内容,个人的一些收获与大家分享一下: Nginx是目前非常流行的web服务器,它起源于俄罗斯.它具有处理速度快,并发量大,占用资源极低等优点,尤其对于静态 ...
- Android 实现书籍翻页效果----升级篇
自从之前发布了<Android 实现书籍翻页效果----完结篇 >之后,收到了很多朋友给我留言,前段时间由于事情较多,博客写得太匆忙很多细节地方没有描述清楚.所以不少人对其中的地方有不少不 ...