Creating enterprise beans using annotations
After you have created your Java or EJB project, you can create session beans, message-driven beans and JPA entities to add to your project.
You need to have a Java project or an EJB project created in your workspace.
In the earlier versions of Enterprise Java bean specifications, two interfaces, home and remote, are defined for accessing the enterprise bean. They can be remote or local depending on the way the client accesses the bean. In EJB 3.0 specification, the home or remote interface is not required: only one interface is defined, the business interface. The business interface is a simple POJI (Plain Old Java Interface) and the type of the business interface (remote or local) is specified using annotations. All annotations required for writing EJB are defined in the javax.ejb package. Using these annotations, you can create session beans, message-driven beans, or entity beans.
- The first step in creating an enterprise bean is to create a simple Java class. Right-click your project, and select
New | Class.
- Add a component-defining annotation, which indicates to the tools that this Java class should be treated as an EJB. Component-defining annotations for EJBs include:
- @Stateless: Component-defining annotation for a stateless session bean.
- @Stateful: Component-defining annotation for a stateful session bean.
- @MessageDriven: Component-defining annotation for a message driven bean.
- Right-click the
Quick-fix icon, and select the appropriate action for you project:
- If this class is contained in a Java project, the tools will provide a quick fix action to help convert this project to an EJB project for you:
Select
Add WAS v7.0 EJB 3.0 support, and your Java project is converted into an EJB 3.0 project, and quick fix and content assist will be available for all EJB 3.0 annotations while in the Java Editor.
- If this class is contained in an EJB project, the tools will provide a quick fix action to add the required import statement:
Select
Import 'Stateless' (javax.ejb), and the import statement import javax.ejb.Stateless; is added to your class.
Related concepts
Related reference