Omnifaces-Exception:CDI BeanManager实例在JNDI中不可用

时间:2016-07-14 07:29:27

标签: cdi jsf-2.2 tomcat8 omnifaces mojarra

我在upserver上部署jsf-application时遇到问题。启动tomcat会导致以下异常:

14-Jul-2016 07:26:52.661 SEVERE [localhost-startStop-1] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment: 
 java.lang.ExceptionInInitializerError
    at org.omnifaces.util.Beans.getManager(Beans.java:88)
    at org.omnifaces.util.Beans.getReference(Beans.java:113)
    at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:70)
    at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89)
    at org.omnifaces.application.OmniApplicationFactory.getApplication(OmniApplicationFactory.java:54)
    at com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:93)
    at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:142)
    at com.sun.faces.lifecycle.ClientWindowFactoryImpl.<init>(ClientWindowFactoryImpl.java:62)
    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:405)
    at javax.faces.FactoryFinderInstance.getImplementationInstance(FactoryFinderInstance.java:251)
    at javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:543)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:283)
    at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:328)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:236)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:439)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:227)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI.
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:97)
    at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:47)
    ... 30 more
Caused by: java.lang.IllegalStateException: javax.naming.NamingException: Cannot create resource instance
    at org.omnifaces.util.JNDI.lookup(JNDI.java:95)
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:93)
    ... 31 more
Caused by: javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:96)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at org.omnifaces.util.JNDI.lookup(JNDI.java:90)
    ... 32 more

14-Jul-2016 07:26:52.665 SEVERE [localhost-startStop-1] org.omnifaces.ApplicationListener.checkCDIAvailable 
????????????????????????????????????????????????????????????????????????????????
?                         ??     ?                                             ?
?    ?                  ?????    ? OmniFaces failed to initialize!             ?
?   ????               ??????    ?                                             ?
?   ??????            ???????    ? This OmniFaces version requires CDI, but    ?
?   ???????          ???????     ? none was found on this environment.         ?
?    ???????????????????????     ?                                             ?
?    ???????????????????????     ? OmniFaces 2.x requires a minimum of JSF 2.2.?
?     ?????????????????????      ? Since this JSF version, the JSF managed bean?
?     ?????????????????????      ? facility @ManagedBean is semi-official      ?
?     ??????????????????????     ? deprecated in favour of CDI. JSF 2.2 users  ?
?     ??????????????????????     ? are strongly encouraged to move to CDI.     ?
?     ??????????????????????     ?                                             ?
?    ???????????????????????     ? OmniFaces goes a step further by making CDI ?
?    ????????????????????????    ? a REQUIRED dependency next to JSF 2.2. This ?
?    ????????????????????????    ? not only ensures that your web application  ?
?   ???????????????? ????????    ? represents the state of art, but this also  ?
?   ?????????????????????????    ? makes for us easier to develop OmniFaces,   ?
?   ??????????????????????????   ? without the need for all sorts of hacks in  ?
?   ??????????????????????????   ? in order to get OmniFaces to deploy on      ?
?  ????????????????????????????  ? environments without CDI.                   ?
?  ????????????????????????????  ?                                             ?
?  ????????????????????????????  ? You have 3 options:                         ?
?????????????????????????????????? 1. Downgrade to OmniFaces 1.x.              ?
?????????????????????????????????? 2. Install CDI in this environment.         ?
?????????????????????????????????? 3. Switch to a CDI capable environment.     ?
??????????????????????????????????                                             ?
?????????????????????????????????? For additional instructions, check          ?
?????????????????????????????????? http://omnifaces.org/cdi                    ?
??????????????????????????????????                                             ?
????????????????????????????????????????????????????????????????????????????????
14-Jul-2016 07:26:52.682 INFO [localhost-startStop-1] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context '/protano'
14-Jul-2016 07:26:52.840 INFO [localhost-startStop-1] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
14-Jul-2016 07:26:52.872 SEVERE [localhost-startStop-1] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment: 
 java.lang.NoClassDefFoundError: Could not initialize class org.omnifaces.config.BeanManager
    at org.omnifaces.util.Beans.getManager(Beans.java:88)
    at org.omnifaces.util.Beans.getReference(Beans.java:113)
    at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:70)
    at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89)
    at org.omnifaces.application.OmniApplicationFactory.getApplication(OmniApplicationFactory.java:54)
    at com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:93)
    at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:142)
    at com.sun.faces.lifecycle.ClientWindowFactoryImpl.<init>(ClientWindowFactoryImpl.java:62)
    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:405)
    at javax.faces.FactoryFinderInstance.getImplementationInstance(FactoryFinderInstance.java:251)
    at javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:543)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:283)
    at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:328)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:236)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:439)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:227)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4840)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

14-Jul-2016 07:26:52.889 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start.

在我当地的环境中工作正常。我已经检查了所有受影响的文件的状态和值:

WEB-INF
- (空)beans.xml

WEB-INF / lib中
-cdi-API-1.2.jar
-weld-servlet的2.2.9.Final.jar

META-INF
context.xml包含以下内容:

 <Context>
   <Resource name="BeanManager" 
      auth="Container"
      type="javax.enterprise.inject.spi.BeanManager"
      factory="org.jboss.weld.resources.ManagerObjectFactory"/>
 </Context>

环境:
java 8
mojarra 2.2.12
omn​​ifaces 2.4
tomcat:8.0.36安装了cdi,仔细按照这里给出的步骤进行:
http://balusc.omnifaces.org/2013/10/how-to-install-cdi-in-tomcat.html

有一个类似的主题没有帮助。对我来说,解决方案尚不清楚。 Omnifaces exception on deployment on Tomcat 7

非常感谢任何其他帮助/建议。

1 个答案:

答案 0 :(得分:1)

当你使用eclipse及其wtp-server-plugin并依赖&#34;清理tomcat工作目录&#34;大部分时间,当部署在生产环境中失败时,您可能忘记清理tomcat的工作文件夹。

删除后 的Tomcat / web应用/ APPNAME
tomcat / webapps / appName.war
的Tomcat /工作

我重新部署,错误消失了。