Java Reference
In-Depth Information
Chapter 5. EJB runtime context, dependency injection, and
crosscutting logic
This chapter covers
• The basics of the EJBContext
• Using JNDI to look up EJBs and other resources
• The @EJB annotation
• EJBs in the application client and embedded containers
• The basics of AOP interceptors
In the previous two chapters we focused on developing session beans and message-driven
beans (MDBs). In this chapter we build on that material and introduce some advanced
concepts applicable to MDBs and session beans. We begin by discussing how containers
provide services behind the scenes and how to access the runtime environment. We then
move on to advanced uses of dependency injection, JNDI lookups, and EJB interceptors. As
you'll learn, EJB 3 largely relieves you of these system-level concerns while providing ex-
tremely robust and flexible functionality when you need it.
5.1. EJB context
EJB components are generally meant to be agnostic of the container. This means that in the
ideal case, EJB components should merely hold business logic and never access the contain-
er or use container services directly. But in rare cases it's necessary for the bean to explicitly
use container services in code. For example, it may be necessary to manually roll back a
transaction or create a timer to execute a business process at some point in the future. These
are the situations the EJB context is designed to handle. The javax.ejb.EJBContext
interface is your backstage entrance into the mystic world of the container. In this section,
we define the EJBContext , explain its use, and show you how to use dependency injection
to retrieve the EJBContext .
Search WWH ::




Custom Search