Using lifecycle methods in interceptors

Methods marked with annotations such as @PreDestroy and @PostConstruct are lifecycle methods. They are invoked during various phases in the lifecycle of an EJB. The @PrePassivate and @PostActivate annotations are also life cycle methods for stateful session beans. Each EJB type has a different set of lifecycle events. These lifecycle methods can also be used in interceptors.

Getting ready

We will be reusing the SimpleInterceptor class as defined in the Defining and using interceptors recipe. In this recipe, we will add a @PostConstruct annotation to illustrate the incorporation of lifecycle methods.

How to do it...

Modify the SimpleInterceptor and add a constructed method annotated with @PostConstruct. In ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.