JSF Named Bean, Eager application scoped (aka @ManagedBean(eager=true) )

断了今生、忘了曾经 提交于 2019-12-23 10:09:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!