As we all know that it is recommended to use annotations from javax.enterprise.context
instead of javax.faces.bean
as they are getting deprecated.
And we all found ManagedBeans with eager="true"
annotated with @ApplicationScoped
from javax.faces.bean
and having a @PostConstruct
method are very useful to do web application initialization e.g: read properties from file system, initialize database connections, etc...
Example :
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.annotation.PostConstruct;
@ApplicationScoped
@ManagedBean(eager=true)
public class someBean{
@PostConstruct
public void init(){
//Do all needed application initialization.
}
...
}
What I want to know is how can I get the same behavior if I used annotations from javax.enterprise.context
.
Note:
@Startup
annotation from javax.ejb
will help to run that code but only at the moment of deployment of the webapp when the application server Starts.
@Eager
should be added to injection point. Based on your answer, I posted an answer below that solves the issue. Thanks. – Tolley