java.lang.IllegalArgumentException: javax.faces.lifecycle.ClientWindowFactory

java.lang.IllegalArgumentException: javax.faces.lifecycle.ClientWindowFactory

我们一直是 运行 开发服务器上的 Web 应用程序,最近有人为我们构建了一个生产服务器(据推测)完全相同的 tomcat 配置,包括 /库目录。当我尝试部署我的应用程序时,新服务器抛出一条相当混乱的错误消息,我希望能帮助理解它。

catalina.out

到目前为止,生产日志和开发日志看起来都很相似:

24-Jun-2015 13:16:47.880 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /opt/fleetforecaster/ff-tomcat/webapps/ROOT.war
24-Jun-2015 13:16:47.903 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
24-Jun-2015 13:16:47.911 WARNING [localhost-startStop-1] org.apache.tomcat.util.digester.SetPropertiesRule.begin [SetPropertiesRule]{Context/Realm} Setting property 'debug' to '99' did not find a matching property.
24-Jun-2015 13:16:52.059 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
24-Jun-2015 13:16:52.180 INFO [localhost-startStop-1] null.null Initializing Mojarra 2.2.5 ( 20140108-1427 https://svn.java.net/svn/mojarra~svn/tags/2.2.5@12761) for context ''
24-Jun-2015 13:16:52.401 INFO [localhost-startStop-1] null.null JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
24-Jun-2015 13:16:52.429 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 18 at position 20
24-Jun-2015 13:16:52.430 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 0 at position 21
24-Jun-2015 13:16:52.431 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 0 at position 22
24-Jun-2015 13:16:52.435 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 18 at position 63
24-Jun-2015 13:16:52.436 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 0 at position 64
24-Jun-2015 13:16:52.437 SEVERE [localhost-startStop-1] null.null Unknow type constant pool 0 at position 65

此时 prod 服务器开始抛出错误:

24-Jun-2015 13:16:52.606 SEVERE [localhost-startStop-1] null.null Critical error during deployment:
 com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! javax.faces.lifecycle.ClientWindowFactory
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:449)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1768)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    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.IllegalArgumentException: javax.faces.lifecycle.ClientWindowFactory
    at javax.faces.FactoryFinder.validateFactoryName(FactoryFinder.java:674)
    at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:368)
    at com.sun.faces.config.processor.FactoryConfigProcessor.setFactory(FactoryConfigProcessor.java:317)
    at com.sun.faces.config.processor.FactoryConfigProcessor.processFactories(FactoryConfigProcessor.java:274)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:216)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:435)
    ... 14 more

后面是第二个错误块:

24-Jun-2015 13:16:52.609 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
24-Jun-2015 13:16:52.621 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
24-Jun-2015 13:16:52.628 SEVERE [localhost-startStop-1] null.null Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory. Attempting to find backup.
24-Jun-2015 13:16:52.628 SEVERE [localhost-startStop-1] null.null Unexpected exception when attempting to tear down the Mojarra runtime
 java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1011)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
    at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:142)
    at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:310)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4774)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5390)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1768)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    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)

两个服务器(据我所知)配置相同 - 它们在 /lib 目录中有 2 个额外的 JSF 和 JSTL 库。

知道这些错误消息是什么意思吗?我必须假设它与 tomcat 安装相关,因为完全相同的 war 在一台服务器上运行良好,但在另一台服务器上运行不正常。

还有一行写着:

    24-Jun-2015 13:16:52.609 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file

我在哪里可以找到“适当的容器日志文件”

两台服务器 - tomcat/lib

jsf-api-2.1.7.jar jsf-impl-2.1.7.jar

两台服务器 - WEB-INF/lib

atmosphere-runtime-2.3.0.jar
commons-codec-1.5.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang-2.6.jar
commons-logging-1.2.jar
dom4j-1.6.1.jar
javaee-web-api-7.0.jar
javax.faces-2.2.5.jar
javax.inject-1.jar
javax.servlet-api-3.0.1.jar
joda-time-2.3.jar
jsf-api-2.1.13.jar
jsf-impl-2.1.13.jar
jstl-1.2.jar
mysql-connector-java-5.1.30.jar
poi-3.10-FINAL.jar
poi-ooxml-3.9.jar
poi-ooxml-schemas-3.9.jar
primefaces-5.1.jar
slf4j-api-1.7.7.jar
stax-api-1.0.1.jar
trove4j-3.0.3.jar
xml-apis-1.0.b2.jar
xmlbeans-2.3.0.jar

Web 应用程序的运行时类路径一团糟。

删除 /WEB-INF/lib

中的那些 JAR
  • javaee-web-api-7.0.jar
  • javax.faces-2.2.5.jar
  • javax.servlet-api-3.0.1.jar

第一个旨在用于编译针对 Java EE 7 容器的 WAR/EAR。它不打算沿着 WAR 安装,目标是像 Tomcat 这样的准系统 JSP/Servlet 容器。它会感到困惑,并认为它实际上是一个 Java EE 7 容器(哦,快乐)。

第二个是 Mojarra 2.2.5(API 和以单一 JAR 形式捆绑的 impl),这是您遇到的最初问题的原因。您基本上是针对早先通过 Tomcat 的 /lib 加载的 JSF 2.1 API 加载 JSF 2.2 实现。 javax.faces.lifecycle.ClientWindowFactory 是自 JSF 2.2 以来新增的(另请参阅 javadoc 中的 @since)并且 JSF 2.1 无法识别 API.

第三个应该是Tomcat自己提供的。请注意,Java EE 7 JAR 还包含 JSF 2.2 和 Servlet 3.1 API。所以这毕竟是 JSF 和 Servlet APIs 的三重冲突(一个 API 来自 Tomcat 的 /lib,一个 API 来自 WAR 的 /WEB-INF/lib,以及 Java EE 7 JAR 包中的一个 API;这不好)。

无论如何,我建议同时清理 Tomcat 的 /lib 并将其保留为默认值。只需坚持使用 WAR 的 /WEB-INF/lib 中的 JAR。而且,如果您 实际上 打算构建一个 JSF 2.2 目标 Web 应用程序(如果匹配,请先仔细检查 versionfaces-config.xml 中),然后保留在 javax.faces-2.2.5.jar 并删除那些 jsf-api-2.1.13.jarjsf-impl-2.1.13.jar 文件。

我遇到了同样的错误,但使用的是 WildFly。不知道为什么,我看不到要添加到我的项目中的 CDI facet 选项。因此,为了抑制此错误消息,我必须在 WEB-INF 文件夹中手动创建 beans.xml。

内容是这样的:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        bean-discovery-mode="all" version="1.1" 
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"/>

干杯

我这边的行为非常奇怪,我遇到了与 wildfly 14 完全相同的问题。

当我在 httpInputText 中重命名我的一个称为验证器的 bean 时,它突然又开始工作了。我将它从 "my_Bean" 重命名为 "myBean" 删除了下划线“_”。

我在 web-inf 下没有 beans.xml。而且我没有对 CDI 使用 Maven 依赖项。这样做很奏效。希望它能为其他人解决一些问题。