CDI

CDI is the Java EE standard(JSR-330) for dependency injection (DI).

Contexts and Dependency Injection for Java EE (CDI) is one of several Java EE features that help to knit together the web tier and the transaction tier of the Java EE platform.

CDI is the spec and its implementation frameworks would provide the functionality. It’s like an analogy JPA and Hibernate.

CDI is an interface defining how to do dependency injection. It’s implementation framework would provide the functionality.

Spring Framework support almost all features of CDI.

  • @Inject –> @Autowired
  • @Named –> @Component & @Qualifier
  • @Singleton –> Defines scope of Singleton.

How to include CDI in our project ??

Add this dependency in pom.xml file.

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

Spring Framework implements CDI.

CDI is Java EE standard.