This application will take you through the basics of Stateful Session Bean. This application will demonstrate how annotations like @Stateful, @Resource, @PostConstruct, @PreDestroy, @PrePassivate, @PostActivate, @Remove are used in an EJB3 application.
Basically a Stateful Session EJB is used whenever there is a requirement to maintain a session. The example is a user registration process wherein the registration process is a two step process. First page prompts to enter your personal credentials and second page prompts to enter your billing and credit card information. The session is maintained till the user has filled up both the jsp pages. Later the complete information is populated on to a database. The application has a Controller servlet which routes the call received from the jsp client to the Bean class, setter methods and jsp pages.
To run this tutorial, as a minimum you will be required to have installed the following prerequisite software.
- Sun JDK 5.0+ (J2SE 1.5)
- Eclipse 220.127.116.11 (Eclipse Classic package of Europa distribution), which is platform specific
- Web Tools Platform (WTP) 2.0.1
- Data Tools Platform (DTP) 1.5.1
- Eclipse Modeling Framework (EMF) 2.3.1
- Graphical Editing Framework (GEF) 3.3.1
Details on installing eclipse are provided in the Development environment section.
This tutorial is organized in the following sections:
Creating a EJB Project
- Right click Under Project Explorer and Select New->EJB Project.
Unable to render embedded object: File (ejb1.png) not found.
- Name the project as StatefulBean. Select Next.
Unable to render embedded object: File (ejb2.png) not found.
- Mark the fields as suggested in the screenshot and Select Next.
Unable to render embedded object: File (ejb3.png) not found.
- Uncheck Generate Deployment Descriptor. This is beacuse we are using annotations is our applications and so deployment descriptors are redundant entity. Select Next.
Unable to render embedded object: File (ejb4.png) not found.
- On next screen select all default values and Select finish.
Unable to render embedded object: File (ejb5.png) not found.
This creates a skeleton for the EJB project. Next steps are adding the bean class, bean interface and setter/getter methods.