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.

Getting ready

Creating a stateless session bean consists of two steps:

  1. Annotate the class with the @Stateless annotation
  2. 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 ...

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.