Accessing the EJB container

An EJB will always reside inside of an EJB. Normally, this container is part of the server. There are times when it is desirable for the EJB to gain access to this container. This access is provided through an instance of the EJBContext interface, which represents the container holding the current bean. The object provides methods to access various aspects of the container including:

  • Security issues
  • Transactions
  • Access to the timer service of the bean
  • References to objects available in the JNDI registry
  • An object allowing the methods of the bean to be invoked

In this recipe we will obtain a SessionContext object for the Salutation EJB developed in the Creating a Simple Session Bean recipe.

How to do it...

The Salutation bean ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.