How do you implement ejbCreate, ejbRemove, ejbActivate and ejbPassivate in EJB 3.0?

Byron Tymvios

There are 4 lifecycle callback methods available in EJB 3.0. They are specified by annotating a method with one of the lifecycle annotations. The annotations are javax.annotation.PostConstruct, javax.annotation.PreDestroy, javax.ejb.PostActivate and javax.ejb.PrePassivate. So you would annotate the methods with @PostConstruct, @PreDestroy, @PostActivate or @PrePassivate. Lifecycle methods must conform to the following rules:

  • method must be pubhlic
  • method must return void
  • method must have no parameters