WAS v8.5 > End-to-end paths > Web services - RESTful services > Use Java contexts and dependency injection with JAX-RSImplement JAX-RS resources with JCDI functionality.
Configure the JAX-RS application.
Step 4 towards the goal: Use Java contexts and dependency injection with JAX-RS
We can use any of the JCDI features separately or with one another to make the applications easier to create, maintain, and test.
Implement JAX-RS resources with dependency injectionUse this method to use dependency injection to separate the creation of new instances of Java types from the use of those Java types in the code. Dependency injection allows for more easily testable code, while also improving the ability to manage applications.
Implement JAX-RS resources with different lifecycle scopesUse this method to use lifecycle scopes to better manage the application code. Lifecycle scopes only apply to managed beans.
Implement JAX-RS resources with decorators and method interceptorsUse this method to write decorators and interceptors for the JAX-RS resource types.
Assemble JAX-RS web applications.
Subtopics
- Implement JAX-RS resources with dependency injection
Contexts and Dependency Injection (JCDI) supports dependency injection in managed beans. By configuring the web application to be JCDI-enabled, we can add @javax.inject.Inject annotated fields and properties. If the annotated fields and properties are valid injection points with valid JCDI managed beans, then their dependencies will be resolved during run time. Dependency injection separates the creation of new instances of Java types from the use of those Java types in the code. Dependency injection can allow for more easily testable code while also improving the ability to manage applications.- Implement JAX-RS resources with different lifecycle scopes
Application developers can use Contexts and Dependency Injection (JCDI) to have different scopes for their managed beans. For instance, if we have an @javax.enterprise.context.ApplicationScoped annotation on a Java class named Foo and multiple @javac.inject.Inject annotated Foo fields in managed beans, there is only one application-scoped Foo instance that actually exists.- Implement a JAX-RS resource with decorators and method interceptors
We can use Java Contexts and Dependency Injection (JCDI) to write interceptors and decorators for Java API for RESTful Web Services (JAX-RS) resource types. For example, we can use the interceptor and decorator capabilities from JCDI to log calls to a particular class or to complete a security check before invoking a method when using JCDI-enabled web applications with JAX-RS.
Related
Implement JAX-RS resources with dependency injection
Implement JAX-RS resources with different lifecycle scopes
Implement a JAX-RS resource with decorators and method interceptors