Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring a Lifecycle Callback Method for an EJB 3.0 MDB

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

- Post-construct: a method called before the first message listener method invocation on the bean. This is at a point after which any dependency injection has been performed by the container.

- Pre-destroy: a method called at the time the bean is removed from the pool or destroyed.

The message-driven bean class method must have the following signature:

    public void <MethodName>()

For more information, see "Callback Methods".

## Using Annotations

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

- `@PostConstruct`

- `@PreDestroy`

Example 10-4 shows how to use the `@PostConstruct` annotation to specify EJB 3.0 message-driven bean class method `initialize` as a lifecycle callback method.

Example 10-4 @PostConstruct in an EJB 3.0 Message-Driven Bean

    @MessageDriven
    public class MessageLogger implements MessageListener
    {
        @Resource javax.ejb.MessageDrivenContext mc;

        public void onMessage(Message message)
        {
        ....
        }

        @PostConstruct
        public void initialize()
        {
            // Initialization logic
        }
    ...
    }