Java Reference
In-Depth Information
ing data from the database on each request would dramatically decrease the scalability of
the site with needless I/O. The code for the
LandingController
is shown in the fol-
lowing listing.
Listing 12.4. Backing bean for homepage
The main focus in this code sample is the
@Inject
annotation on the
itemManager
. When the
LandingController
is instantiated, CDI will retrieve an instance of the
itemManager
from the EJB container;
itemManager
is a stateless session bean. After
injection, the CDI container will then invoke the method annotated with
@PostCon-
struct
. Note that in this case you could easily have used the
@EJB
annotation in-
stead. But you could have injected almost any other POJO, and you'll see this as the chapter
proceeds. The next listing illustrates another permutation of the
@Inject
annotation using
constructor injection.