开发者

JSF2.0 PostConstructApplicationEvent managed bean is null

We have JSF2.0 in Tomcat6.0 , need to initialize a ApplicationScope Bean while web server is started.

I tried using the PostConstructApplicationEvent processEvent method to initialize the Bean , but the managed bean from faces-config.xml is returning null.

Is there any other better way to instantiate the bean after start开发者_如何学Pythonup?


Remove any faces-config.xml declarations related to the bean (they will otherwise override the JSF 2.0 annotations) and then annotate the bean with @ManagedBean(eager=true) as follows:

@ManagedBean(eager=true)
@ApplicationScoped
public class Bean {
    // ...
}

This way the bean will always be instantiated on JSF webapp startup, without the need to view any page. You can then do the initialization job in the constructor and/or @PostConstruct of the bean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜