title: java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager'
body: <p>After build a lot of converters in my JSF app, I turned my attention to Omnifaces and everything's working like a charm. The problem arises when I deploy my application. The first time I access to my login page, it throws the next exception:</p>
  
  <pre><code>    SEVERE: BeanManager enum singleton failed to initialize.
      java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Error retrieving java:comp/BeanManager [Root exception is java.lang.IllegalStateException: Cannot resolve bean manager]]
              at org.omnifaces.util.JNDI.lookup(JNDI.java:87)
              at org.omnifaces.config.BeanManager.init(BeanManager.java:76)
              at org.omnifaces.config.BeanManager.getReference(BeanManager.java:115)
              at org.omnifaces.application.OmniApplication.createValidator(OmniApplication.java:105)
              at com.sun.faces.component.validator.ComponentValidators.addValidatorsToComponent(ComponentValidators.java:280)
              at com.sun.faces.component.validator.ComponentValidators.addDefaultValidatorsToComponent(ComponentValidators.java:147)
              at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.processValidators(ComponentTagHandlerDelegateImpl.java:550)
              at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.privateOnComponentPopulated(ComponentTagHandlerDelegateImpl.java:531)
              at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:195)
              at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
              at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
              at com.sun.faces.facelets.tag.jsf.core.MetadataHandler.apply(MetadataHandler.java:104)
              at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
              at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
              at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
              at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
              at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:116)
              at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:233)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
              at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
              at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
              at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
              at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
              at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
              at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
              at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
              at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
              at org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage(FormAuthenticator.java:464)
              at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:253)
              at com.sun.web.security.RealmAdapter.invokeAuthenticateDelegate(RealmAdapter.java:1333)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551)
              at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:623)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
              at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
              at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
              at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
              at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
              at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
              at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
              at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
              at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
              at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
              at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
              at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
              at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
              at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
              at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
              at java.lang.Thread.run(Thread.java:662)
      Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Error retrieving java:comp/BeanManager [Root exception is java.lang.IllegalStateException: Cannot resolve bean manager]]
              at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
              at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.omnifaces.util.JNDI.lookup(JNDI.java:83)
              ... 53 more
      Caused by: javax.naming.NamingException: Error retrieving java:comp/BeanManager [Root exception is java.lang.IllegalStateException: Cannot resolve bean manager]
              at org.glassfish.weld.BeanManagerNamingProxy.handle(BeanManagerNamingProxy.java:129)
              at com.sun.enterprise.naming.impl.NamedNamingObjectManager.tryNamedProxies(NamedNamingObjectManager.java:89)
              at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:174)
              at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
              ... 57 more
      Caused by: java.lang.IllegalStateException: Cannot resolve bean manager
              at org.glassfish.weld.BeanManagerNamingProxy.handle(BeanManagerNamingProxy.java:119)
              ... 60 more
  </code></pre>
  
  <p>However, when I refresh my page, everything works fine.</p>
  
  <p>Any ideas? Regards !!!</p>
  
  <p>I'm using Glassfish 3.1.2.2 with JSF 2.1</p>