Contexts and Dependency Injection Framework
Learn how to replace Spring annotations with CDI annotations.
We'll cover the following
Contexts and Dependency Injection (CDI) is an interface that standardizes dependency injection for Java EE. It defines different annotations for dependency injection like @Named
, @Inject
, @Scope
, @Singleton
, etc. Different CDI implementation frameworks provide support and functionality for these annotations.
@Named
is used to define a bean and @Inject
is used for autowiring one bean into another. Spring supports most of the annotations defined by CDI.
For the code example shown in this lesson, we have created a sub-package called lesson12
inside the package io.datajek.spring.basics.movierecommendersystem
.The package contains MovieRecommenderSystemApplication.java
, Filter.java
, ContentBasedFilter.java
, CollaborativeFilter.java
, and RecommenderImplementation.java
files.To be able to use CDI annotations in our Spring application, we need to add a dependency in the pom.xml
file as follows:
Get hands-on with 1400+ tech skills courses.