|
Callbacks has been created by David Blevins (Sep 11, 2007). Content:Correct usage of PostConstruct, PreDestroy, PrePassivate, PostActivate, and AroundInvoke for EJBs and Interceptors. Statelessimport javax.ejb.Stateless; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; @Stateless public class MyStatelessBean implements MyBusinessInterface { @PostConstruct public void constructed(){ } @PreDestroy public void destroy(){ } @AroundInvoke public Object invoke(InvocationContext invocationContext) throws Exception { return invocationContext.proceed(); } } Statefulimport javax.ejb.Stateful; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; @Stateful public class MyStatefulBean implements MyBusinessInterface { @PostConstruct public void constructed(){ } @PreDestroy public void destroy(){ } @AroundInvoke public Object invoke(InvocationContext invocationContext) throws Exception { return invocationContext.proceed(); } @PostActivate public void activated(){ } @PrePassivate public void passivate(){ } } MessageDrivenimport javax.ejb.MessageDriven; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; @MessageDriven public class MyMessageDrivenBean implements MyListenerInterface { @PostConstruct public void constructed(){ } @PreDestroy public void destroy(){ } @AroundInvoke public Object invoke(InvocationContext invocationContext) throws Exception { return invocationContext.proceed(); } } Interceptorimport javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.interceptor.InvocationContext; import javax.interceptor.AroundInvoke; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; public class MyInterceptor { @PostConstruct public void constructed(InvocationContext invocationContext){ } @PreDestroy public void destroy(InvocationContext invocationContext){ } @AroundInvoke public Object invoke(InvocationContext invocationContext) throws Exception { return invocationContext.proceed(); } @PostActivate public void activated(InvocationContext invocationContext){ } @PrePassivate public void passivate(InvocationContext invocationContext){ } } |
Powered by
Atlassian Confluence
(Version: 2.2.9 Build:#527 Sep 07, 2006)
-
Bug/feature request
Unsubscribe or edit your notifications preferences
Unsubscribe or edit your notifications preferences
