Accessing a session bean using dependency injection
A session bean has limited value by itself. To be useful it needs to be used by a client such as a servlet or JSF page. In this recipe we will see how to use dependency injection to use a session bean in a servlet.
The essential steps to access a session EJB using dependency injection include:
- Inject the EJB using the @EJB annotation
- Access its methods as needed
First we need a session bean. To keep things simple, we will use the Salutation session EJB developed in the previous recipe. We will add our servlet to the
How to do it...
We will be developing a HyperText Transfer Protocol (HTTP) based servlet named
SalutationServlet. This servlet will use the