java.lang.IllegalStateException:javax.naming.NamingException:'java:comp / BeanManager'查找失败

时间:2014-02-25 22:25:25

标签: jsf glassfish-3 cdi omnifaces

在我的JSF应用程序中构建了很多转换器后,我把注意力转向了Omnifaces,一切都像魅力一样。部署我的应用程序时出现问题。我第一次访问我的登录页面时,会抛出下一个异常:

    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

但是,当我刷新页面时,一切正常。

有什么想法吗?问候!!!

我正在使用Glassfish 3.1.2.2和JSF 2.1

2 个答案:

答案 0 :(得分:4)

如果webapp在部署到隐式启用CDI的服务器(例如您的GlassFish 3)中未显式启用CDI,则会抛出此错误。自OmniFaces 1.8以来,这已得到修复。另一种方法是通过创建/WEB-INF/beans.xml文件在您的webapp中明确启用CDI。

答案 1 :(得分:0)

我在尝试运行Payara 4.1应用程序时遇到此异常。实际上我可以互换地获得以下2:

Exception 0 :
org.jboss.weld.exceptions.UnserializableDependencyException: WELD-001413: The bean Managed Bean [class com.baw.website.beans.quality.ui.AuditBean] with qualifiers [@Default @Any @Named] declares a passivating scope but has a non-passivation-capable dependency Managed Bean [class com.baw.website.rest.clients.AuthUtil] with qualifiers [@Any @Default]

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:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at org.omnifaces.util.JNDI.lookup(JNDI.java:90)

经过分析,我发现在不同的包中有两个同名的类:

com.mycompany.mypackageone.Myclass

com.mycompany.mypackagetwo.Myclass

其中一个是CDI注入到ManagedBean中,该ManagedBean与使用Omnifaces的JSF页面相关。我不确定冲突发生在哪里(我确实有一个beans.xml)。但对我来说,停止/启动Payara,重命名两个同名的类中的一个就可以解决问题并摆脱错误。