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. 【BJG吐槽汇】第一期 - 警惕亚马逊莫名自动扣款!千万不要进了它的坑!

    BJG吐槽汇:一直以来我都觉得其实生活中工作中会有各种各样奇葩的事或者奇葩的人可以去吐槽,那么BeJavaGod本身聊得就是关于JavaWeb技术,互联网技术,互联网产品等,那么今天起咱们开了这么一档 ...

  2. Java学习笔记(七):内部类、静态类和泛型

    内部类 在Java中,可以将一个类定义在另一个类里面或者一个方法里面,这样的类称为内部类.广泛意义上的内部类一般来说包括这四种:成员内部类.局部内部类.匿名内部类和静态内部类.下面就先来了解一下这四种 ...

  3. CSS 的 appearance 属性

    在 Firefox 1.0+,Chrome 1.0+ 和 Safari 3.0+ 中,我们可以使用 -moz-appearance 或者 -webkit-appearance 属性让元素模仿系统原生控 ...

  4. sql:[dbo].[smt_MES_RptProductDaily] 生产日报表

    USE [ChangHongMES_904]GO/****** Object: StoredProcedure [dbo].[smt_MES_RptProductDaily] Script Date: ...

  5. DotNetZip封装类

      DotnetZip是一个开源类库,支持.NET的任何语言,可很方便的创建,读取,和更新zip文件.而且还可以使用在.NETCompact Framework中. 下载地址在这里: http://d ...

  6. android ipc通信机制之二序列化接口和Binder

    IPC的一些基本概念,Serializable接口,Parcelable接口,以及Binder.此核心为最后的IBookManager.java类!!! Serializable接口,Parcelab ...

  7. php 处理高并发的思路

    1.nginx 服务器,提高网站服务器并发性能 2.控制大文件的下载,减少CPU的消耗. 3.对于sql查询做缓存. 4.静态页面文件缓存. 5.CND缓存静态文件, 6.反向代理到多个服务器,用来分 ...

  8. 关于Struts2的客户端校验的FreeMarker template error!

    把<s:form action="login" namespace="/" validate="true" >改为 <s: ...

  9. 【转】Watir, Selenium & WebDriver

    转自:http://watirmelon.com/2010/04/10/watir-selenium-webdriver/ Please also see my new ‘Watir-WebDrive ...

  10. &lt;Android&gt;关于EditText中setInputType和setSingleLine的冲突

    近期自己开发了一个带有删除button的EditText,一方面须要设置为SingleLine,还有一方面又须要设置输入类型,起先在xml文件里设置了android:inputType类型,在自己定义 ...