When running with an active CDI container, the bean is created and injected by CDI like any other CDI-managed
type: fields and properties annotated with @Inject are injected normally, and
fields and properties annotated with one of the @XxxParam annotations (@PathParam,
@FormParam ...) are resolved from the current request context using the same CDI qualifier
mechanism used for resource method parameters.
Without an active CDI container, the JAX-RS runtime instantiates the object and injects all its fields and
properties annotated with one of the @XxxParam annotations. For the POJO classes the same instantiation
and injection rules apply as in the case of instantiation and injection of request-scoped root resource classes.
public class MyBean {
@FormParam("myData")
private String data;
@HeaderParam("myHeader")
private String header;
@PathParam("id")
public void setResourceId(String id) {...}
...
}
@Path("myresources")
public class MyResources {
@POST
@Path("{id}")
public void post(@BeanParam MyBean myBean) {...}
...
}
Because injection occurs at object creation time, use of this annotation on resource class fields and bean properties is only supported for the default per-request resource class lifecycle. Resource classes using other lifecycles should only use this annotation on resource method parameters.
- Since:
- 2.0
- Author:
- Marek Potociar
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSupports inline instantiation of theBeanParamannotation.