Chapter 5. Learning advanced EJB concepts

 

This chapter covers

  • EJB internals
  • Dependency injection of the @Resource annotation
  • Crosscutting concerns with interceptors
  • Task scheduling with the EJB timer

In the previous two chapters we focused on developing session beans and message-driven beans (MDBs). Although we discussed a few bean type-specific features in detail, we generally avoided covering topics not closely related to introducing the basics. In this chapter we build on the material in the previous chapters and introduce advanced concepts applicable to MDBs and session beans. It is very likely that you’ll find these EJB 3 features extremely helpful while using EJB in the real world.

We begin by discussing the how containers provide the services behind the scenes and how to access environment information. We then move on to advanced use of dependency injection, JNDI lookups, EJB interceptors, and the EJB timer service. As you’ll learn, EJB 3 largely relieves you from these system-level concerns while providing extremely robust and flexible functionality.

As a foundation for the rest of the chapter, we briefly examine these EJB internals first.

5.1. EJB internals

5.2. Accessing resources using DI and JNDI

5.3. AOP in the EJB world: interceptors

5.4. Scheduling: the EJB 3 timer service

5.5. Summary