Injection can be applied on fields, constructor parameters, resources, subresources, subresource locators, method parameters, and setter methods. It helps to identify which path or parameter of the request needs to be handled. Let's look at the following examples:
Root-resource:
@Path("/userService") public class UserResource { ... }
Fields:
@Path("/userService") public class UserResource { ... @QueryParam("name") private String name; ... }
Constructor parameter:
@Path("/userService") public class UserResource { public UserResource(@PathParam("id") int id){ ... } @GET @Path("{id}") public String getUser() { ... } }
Resource method:
@Path("/userService") public class UserResource { @GET public String getUser(@QueryParam("name")String name) { ... } }
Subresource method:
@Path("/userService") public class UserResource { @GET @Path("/getUser/{name}") public String getUser(@PathParam("name"...