You can use eager=true in the @ManagedBean .
@ManagedBean(eager=true) @ApplicationScoped public class Config {
Thus, the bean will be auto-acces when launching webapp.
Instead, you can also use Application#evaluateExpressionGet() to programmatically evaluate EL and therefore automatically create a bean. See also an example of this answer .
FacesContext context = FacesContext.getCurrentInstance(); Confic config = (Config) context.getApplication().evaluateExpressionGet(context, "#{config}", Config.class); // ...
You can also just enter it as @ManagedProperty bean where you need it.
@ManagedBean @RequestScoped public class Register { @ManagedProperty("#{config}") private Config config; @PostConstruct public void init() {
JSF will automatically create it before injection into the parent bean. It is available in all methods besides @PostConstruct .
source share