Accessing the session bean using JNDI
JNDI can also be used to access an EJB but using this technique is not as easy as DI. The
Salutation EJB from the first recipe and the servlet from the second recipe are used to illustrate this technique.
To use JNDI in a client:
- Obtain an InitialContext object
- Use the context to look up the EJB
Familiarize yourself with the
Salutationsession bean and its two methods as developed in the Creating a Simple Session EJB recipe. We will also modify the
SalutationServletfrom the second recipe to use JNDI instead of DI.
How to do it...
A portable JNDI name syntax has been added to EJB 3.1. We will use this syntax as it makes the use of JNDI less dependent on the deployment server.
The modification of the ...