In my previous blog I was writing about the CDI annotation in EE 6, in this blog I will write about the The Common Annotations, namely:
Resource Injection:
Lifecycle:
Managed Bean:
The @Resource and @Resources are shortcut for doing jndi lookup, e.g. new new InitialContext().lookup(name).
The @PostConstruct and @PreDestroy are neat annotation to do initialization and clean up in a standardized way. I would recommend to use these annotation even if you are not deploying to an enterprise environment. The above annotation can be used on any bean, such EJB, MDB, Managed Bean, but if you annotate a POJO, you need to fetch that POJO with @Inject to make the PostConstruct and PreDestroy be called.
This annotation should NOT be mixed up with javax.faces.bean.ManagedBean or JMX Managed Bean. It is a lightweight component that enables resource injection, lifecycle callbacks and interceptors. I my self is not totally sure where this component fits in, but it's there.
No comments:
Post a Comment