Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 873
vizzdoom Avatar asked Oct 19 '11 22:10

vizzdoom


1 Answers

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

like image 154
Rudy De Busscher Avatar answered Oct 23 '22 12:10

Rudy De Busscher