JSF命名Bean,受Eager应用程序限制(又名@ManagedBean(eager = true)) [英] JSF Named Bean, Eager application scoped (aka @ManagedBean(eager=true) )

查看:177
本文介绍了JSF命名Bean,受Eager应用程序限制(又名@ManagedBean(eager = true))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过javax.faces包中的@ManagedBean(eager=true)初始化由javax.inject.Named/javax.enterprise.context.ApplicationScoped注释的命名Bean?

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() { ... }

我想在应用程序启动时加载此类,而不是在Web应用程序引用该bean时加载.

I want to load this class when application starts, not when webapplication refers to this bean.

ps. JSF 2.1
Glassfish 3.1注入的咖啡豆

ps. JSF 2.1
Bean Injected by Glassfish 3.1

推荐答案

您可以创建一个CDI扩展,该扩展在其方法之一中具有@Observes AfterBeanDiscovery参数.您可以在那里实例化bean,从而在容器启动时对其进行初始化. CODI使您更轻松地进行这些操作,请参见 https://cwiki .apache.org/confluence/display/EXTCDI/Core + Usage#CoreUsage-Startup

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

这篇关于JSF命名Bean,受Eager应用程序限制(又名@ManagedBean(eager = true))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆