Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring a Lifecycle Callback Method for an EJB 3.0 Session Bean

You can specify an EJB 3.0 session bean class method as a callback method for any of the following lifecycle events (see "Using Annotations"):


Note:

Do not specify pre-passivate or post-activate lifecycle callback methods on a stateless session bean.

The session bean class lifecycle callback method must have the following signature:

public void <MethodName>()

For more information, see "Callback Methods".

Using Annotations

You can specify an EJB 3.0 session bean class method as a lifecycle callback method using any of the following annotations:

  • @PostConstruct

  • @PreDestroy

  • @PrePassivate (stateful session beans only)

  • @PostActivate (stateful session beans only)

Example 5-1 shows how to use the @PostConstruct annotation to specify EJB 3.0 stateful session bean class method initialize as a lifecycle callback method.

Example 5-1 @PostConstruct

@Stateful
public class CartBean implements Cart
{
    private ArrayList items;
 
    @PostConstruct
    public void initialize()
    {
        items = new ArrayList();
    }
...
}