Mastering Spring 5.0
上QQ阅读APP看书,第一时间看更新

Exploring Contexts and dependency injection

CDI is Java EE's attempt at bringing DI into Java EE. While not as fully-fledged as Spring, CDI aims to standardize the basics of how DI is done. Spring supports the standard annotations defined in JSR-330. For the most part, these annotations are treated the same way as Spring annotations.

Before we can use CDI, we will need to ensure that we have dependencies for CDI jars included. Here's the code snippet:

    <dependency> 
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

In this table, let's compare the CDI annotations with the annotations provided by Spring Framework. It should be noted that @Value, @Required, and @Lazy Spring annotations have no equivalent CDI annotations.