我使用的是 Tomcat 8 (8.0.30)、OpenWebBeans 1.6.2、JSF Mojarra 2.2.12 和 OmniFaces 1.8。我决定将 OmniFaces 升级到更高版本。在 2.0 之后,它似乎需要 CDI,但是在启动 Tomcat(使用 OmniFaces 2.2)时,出现以下错误。根据 OmniFaces 的兼容性矩阵,Tomcat+Mojarra+OWB 应该适用于 8.0.30+2.2.12+1.6.2。
我也尝试过 2.0,但同样的错误。在 2.1 中我遇到了另一个问题,但我只是假设它在 2.2 中是固定的,因为那里的行为与 2.0 中的相同。我对 2.3-RC1 也有同样的问题。
是否需要做一些具体的事情才能让 OmniFaces 识别我正在运行 CDI?这可能是 OmniFaces 中的错误吗?
我创建了一个非常小的示例应用程序来复制这个问题,所以我确信我们的主应用程序中没有其他任何干扰。
mar 22, 2016 10:57:46 FM org.apache.webbeans.lifecycle.AbstractLifeCycle bootstrapApplication
INFO: OpenWebBeans Container has started, it took [447] ms.
mar 22, 2016 10:57:46 FM org.omnifaces.ApplicationListener checkCDIAvailable
SEVERE:
????????????????????????????????????????????????????????????????????????????????
? ?? ? ?
? ? ????? ? 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 ?
?????????????????????????????????? ?
????????????????????????????????????????????????????????????????????????????????
mar 22, 2016 10:57:46 FM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.omnifaces.ApplicationListener
java.lang.ExceptionInInitializerError
at org.omnifaces.ApplicationListener.checkCDIAvailable(ApplicationListener.java:74)
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:58)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI.
at org.omnifaces.config.BeanManager.<init>(BeanManager.java:99)
at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:49)
... 11 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:95)
... 12 more
Caused by: javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.omnifaces.util.JNDI.lookup(JNDI.java:90)
... 13 more
这是我正在使用的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.app.testapp</groupId>
<artifactId>sampleapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
</dependency>
</dependencies>
</project>