Using CDI to inject context and dependency
Context and Dependency Injection for Java EE (CDI) is one of the most important APIs under the Java EE umbrella. Introduced in Java EE 6, it now has a big influence over many other APIs.
In the recipe, you will learn how to use CDI in a couple of different ways and situations.
Getting ready
First, let's add the required dependency needed:
<dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
How to do it...
- We are going to build a JAX-RS based application, so we will start by preparing the application to perform:
@ApplicationPath("webresources") public class Application extends...