Java Reference
In-Depth Information
that if your application is load-balanced across multiple servers, you have to be careful. In
the example here where events to notify the LandingController about a new item are
used, this wouldn't scale in a multiserver environment. Each server would have a different
list of new items. In this situation, JMS is thus a more appropriate solution. But CDI events
can be used with JMS. A message-driven bean could receive a new listing and then send
out a CDI event to all beans within the server, thereby solving the problem.
There's one area where a CDI supplants EJBs and that's with stateful session beans. Con-
versationally, scoped beans are much easier to use and more appropriate for most applica-
tions. In the past, most stateful session beans were being used to implement a long-running
business process, or what we'd now term a conversation. Conversations are only the start;
CDI supports the creation of custom scopes, which are much more flexible and lend them-
selves to creative and elegant solutions that are much easier to maintain.
12.9. Summary
In this chapter we examined the basics of CDI, and you learned what constitutes a CDI
bean and the relationship between CDI beans, EJBs, and JSF-backing beans. We covered
the various CDI scopes, including request, session, and conversation. Although it was bey-
ond the scope of this chapter, CDI supports custom scopes, which are useful for implement-
ing specific business processes. We covered in depth one of the most important features:
dependency injection. Dependency injection in CDI uses Java type information, not free-
form text strings. You learned that CDI's dependency injection was much more expansive
than that of EJB—it can be used by constructors, for example. We delved into producer
methods with an important side note about the interaction between CDI and JPA. Both in-
terceptors and decorators were covered. Decorators are a specialized type of interceptor
tied to an interface. We also looked at qualifiers and how qualifiers are used to distinguish
between different instances of the same type—for example, a new item versus the current
item you're bidding on. CDI uses qualifiers to figure out what instance you want injected.
We then built on these concepts with a detailed overview of events and a complex example
of conversations.
There are a couple of important points that we must emphasize. CDI isn't a replacement
for EJBs, and is agnostic when it comes to web frameworks. Although CDI replaces JSF-
backing beans, it isn't tied to JSF, nor is there anything JSF-specific in CDI. The @Named
Search WWH ::




Custom Search