JSF 2.3-Servlet 4-JavaEE 8和Tomcat9:找不到CDI BeanManager

时间:2018-11-22 14:54:38

标签: java tomcat jsf cdi jsf-2.3

我试图从JSF 2.1迁移到2.3 / Servlet 4 / Tomcat 9,但是在配置CDI时遇到了一些麻烦。 我遵循了BalusC的this guide在Tomcat 9上启用CDI(以我为例),但是在启动我的应用程序时仍然出现此异常:

com.sun.faces.config.ConfigurationException: Factory 'javax.faces.lifecycle.ClientWindowFactory' was not configured properly.
    at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:357)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:243)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:443)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:237)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4641)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5109)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1737)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:457)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:406)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.faces.FacesException: Unable to find CDI BeanManager
    at com.sun.faces.application.ApplicationImpl.isJsf23(ApplicationImpl.java:2714)
    at com.sun.faces.application.ApplicationImpl.addELResolver(ApplicationImpl.java:549)
    at javax.faces.application.ApplicationWrapper.addELResolver(ApplicationWrapper.java:611)
    at javax.faces.application.ApplicationWrapper.addELResolver(ApplicationWrapper.java:611)
    at org.jboss.weld.environment.servlet.jsf.WeldApplication.<init>(WeldApplication.java:72)
    at org.jboss.weld.environment.servlet.jsf.WeldApplicationFactory.getApplication(WeldApplicationFactory.java:46)
    at com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:88)
    at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:153)
    at com.sun.faces.lifecycle.ClientWindowFactoryImpl.<init>(ClientWindowFactoryImpl.java:63)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at javax.faces.FactoryFinderInstance.getImplGivenPreviousImpl(FactoryFinderInstance.java:391)
    at javax.faces.FactoryFinderInstance.getImplementationInstance(FactoryFinderInstance.java:255)
    at javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:529)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:292)
    at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:354)
    ... 48 more

请注意,在遵循指南之前,我有相同的例外,但是它是从另一个类(com.sun.faces.el.ELUtils.java方法tryAddCDIELResolver(FacesCompositeELResolver composite))引发的,而在指南之后是从com.sun.faces.application.ApplicationImpl.java方法{{ 1}}。 我的图书馆版本是:

private boolean isJsf23()

有人可以告诉我我在做什么错吗? 非常感谢。

编辑

试图找到 <icefaces-ace.version>3.2.0</icefaces-ace.version> <javax.jms-api.version>2.0.1</javax.jms-api.version> <el-api.version>2.2</el-api.version> <javax.el-api.version>3.0.0</javax.el-api.version> <jstl.version>1.2</jstl.version> <javax.faces-api.version>2.3</javax.faces-api.version><!--JSF API--> <javax.faces.version>2.3.8</javax.faces.version> <!--Mojarra--> <javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version> <javax.servlet-api.version>4.0.1</javax.servlet-api.version> <javax.servlet.jsp.jstl-api.version>1.2.2</javax.servlet.jsp.jstl-api.version> <javaee-web-api.version>8.0</javaee-web-api.version> <weld-servlet-shaded.version>3.0.5.Final</weld-servlet-shaded.version> 的这段代码是:

BeanManager

我添加了一些断点来检查 public static BeanManager getCdiBeanManager(FacesContext facesContext) { BeanManager result = null; if (facesContext != null && facesContext.getAttributes().containsKey(RIConstants.CDI_BEAN_MANAGER)) { result = (BeanManager) facesContext.getAttributes().get(RIConstants.CDI_BEAN_MANAGER); } else if (facesContext != null && facesContext.getExternalContext().getApplicationMap().containsKey(RIConstants.CDI_BEAN_MANAGER)) { result = (BeanManager) facesContext.getExternalContext().getApplicationMap().get(RIConstants.CDI_BEAN_MANAGER); } else { try { InitialContext initialContext = new InitialContext(); result = (BeanManager) initialContext.lookup("java:comp/BeanManager"); } catch (NamingException ne) { try { InitialContext initialContext = new InitialContext(); result = (BeanManager) initialContext.lookup("java:comp/env/BeanManager"); } catch (NamingException ne2) { } } if (result == null && facesContext != null) { Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap(); result = (BeanManager) applicationMap.get("org.jboss.weld.environment.servlet.javax.enterprise.inject.spi.BeanManager"); } if (result != null && facesContext != null) { facesContext.getAttributes().put(RIConstants.CDI_BEAN_MANAGER, result); facesContext.getExternalContext().getApplicationMap().put(RIConstants.CDI_BEAN_MANAGER, result); } } return result; } null result' and it is really facesContext`不是。

0 个答案:

没有答案