Creating a stateless session bean
In this recipe we will create a stateless session bean called
SphereBean. This bean will demonstrate the essential elements of a stateless bean and its life cycle. The servlet
SphereServlet will be used to demonstrate the bean.
Creating a stateless session bean consists of two steps:
- Annotate the class with the @Stateless annotation
- Add appropriate business methods
Earlier versions of EJB required the use of local and/or remote interfaces. This is no longer necessary.
To use a session bean, inject the EJB into the client using the @EJB annotation followed by the declaration of the bean. In this recipe, we will use a servlet to demonstrate this process. It is important to use the @EJB annotation, otherwise ...