问题
Is there any way to initialize Named Bean annotaded by javax.inject.Named
/javax.enterprise.context.ApplicationScoped
like @ManagedBean(eager=true)
from javax.faces
package?
@Named
@ApplicationScoped
public Mail() { ... }
I want to load this class when application starts, not when webapplication refers to this bean.
ps. JSF 2.1
Bean Injected by Glassfish 3.1
回答1:
You can create a CDI extension that has the @Observes AfterBeanDiscovery parameter on one of his methods. There you can instantiate the bean and thus initialize it when the container starts up. CODI has made those things easier for you, see https://cwiki.apache.org/confluence/display/EXTCDI/Core+Usage#CoreUsage-Startup
来源:https://stackoverflow.com/questions/7828987/jsf-named-bean-eager-application-scoped-aka-managedbeaneager-true