You can use the Create EJB 3.x Session Bean wizard to create
a stateful session bean and add it to your project.
Before you begin
You must have a Java™ project,
an EJB project, or a web project created in your workspace.
Procedure
- In the Java EE perspective,
right-click your project, and select . The Create EJB
3.x Session Bean wizard opens.
- In the Source folder field, select
the source folder for the new bean.
- In the Java package field, type
the package name for the new bean.
- In the Bean name field, type the name that you want
to assign to the enterprise bean. By convention, bean names begin
with an uppercase letter.
Note: You can use Unicode characters
for the bean name, but Unicode characters are not supported for enterprise
bean packages and classes associated with enterprise beans.
- Select Remote to add a remote interface
and select Local to add a local interface, and click Finish.
- In the Java class
editor, underneath the package declaration, you can see the @Stateful annotation.
Your class also contains reference to Local and Remote interfaces,
if you selected to create them:
package com.ibm.test;
import javax.ejb.Stateful;
/**
* Session Bean implementation class TestBean
*/
@Stateful
public class TestBean implements TestBeanRemote, TestBeanLocal {
/**
* Default constructor.
*/
public TestBean() {
// TODO Auto-generated constructor stub
}
}
- Define the client views and interfaces. For EJB 3.0 or
later beans, you can include a remote client interface, a local interface,
or both. Here is an example of a simple Remote interface:
package com.ibm.websphere.ejb3sample.counter;
import javax.ejb.Remote;
@Remote
public interface RemoteCounter {
public int increment();
public int getTheValue();
}