zoukankan      html  css  js  c++  java
  • Jersey(1.19.1)

    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.

  • 相关阅读:
    Qt Quick实现的涂鸦程序
    Java并发学习之十九——线程同步工具之Phaser
    poj 1845(等比数列前n项和及高速幂)
    装饰模式(旧恋)
    cocos2d-x 3.1.1 学习笔记[3]Action 动作
    Nmap 源代码学习四 软件简单使用
    关于phpcmsv9更新缓存出现链接被重置的问题
    POJ 3159 Candies(SPFA+栈)差分约束
    Ubuntu 配置ISCSI服务
    iSCSI存储技术
  • 原文地址:https://www.cnblogs.com/huey/p/5399836.html
Copyright © 2011-2022 走看看