Probably my question is a trivial one, but I never used an application scope bean before. I need the application bean because I have to do time consuming transactions on the database. my search didn't satisfy my curiosity at all. I don't know why but I didn't manage to initialize the bean (it is null) or it the app crashed. So I have an application scope bean
@ManagedBean(eager=true)
@ApplicationScoped
public class ApplicationContainer {
...
}
eager=true I read that tells JSF to initiate the bean every time when the application server (I use GlassFish) is started.
I read in several places that I just have to put this annotation and the bean gets initialized. For me it doesn't... After I read that if I want to inject the application bean into another bean I have to use @PostConstuct annotation
@ManagedBean
@SessionScoped
public class TestsBean implements Serializable {
private static final long serialVersionUID = 1L;
@ManagedProperty(value = "#{container}")
private ApplicationContainer container;
@PostConstruct
public void init() {
container.contructContainer();
}
this gives an error in other bean that I inject the TestsBean into...
- if the application bean gets initialized when the server starts what method does it call in the body of the application bean to do the actions that it requires? Or in the injected bean it's done in the post construct method?
Please tell me the proper way to handle application beans. I an really confused...
Thank you all for your time!