为什么 WildFly 10 + JSF 2.3 不能与 Omnifaces 2.6.1 一起使用?

Why is WildFly 10 + JSF 2.3 not working with Omnifaces 2.6.1?

我一直在尝试在 Wildfly 10 上使用 jsf 2.3、primefaces 6 和 omnifaces 2.6.1 启动应用程序并运行。

我已经拆分了 jsf 2.3(api 和 impl)并完成了 WildFly 的设置。

应用程序在没有 omnifaces 2.6.1 的情况下顺利启动。但是当我将 omnifaces jar 添加到应用程序类路径 (/lib) 时,这个 jar 在启动时失败,给出下一个异常:

13:21:52,024 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 78) Critical error during deployment: : com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:457)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:237)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:200)
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:171)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:82)
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)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
    Caused by: java.lang.UnsupportedOperationException
at javax.faces.application.Application.getSearchExpressionHandler(Application.java:2001)
at javax.faces.application.ApplicationWrapper.getSearchExpressionHandler(ApplicationWrapper.java:815)
at com.sun.faces.config.processor.ApplicationConfigProcessor.setSearchExpressionHandler(ApplicationConfigProcessor.java:738)
at com.sun.faces.config.processor.ApplicationConfigProcessor.process(ApplicationConfigProcessor.java:382)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:155)
at com.sun.faces.config.processor.LifecycleConfigProcessor.process(LifecycleConfigProcessor.java:138)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:155)
at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:246)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:443)
... 21 more
    13:21:52,031 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 78) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:85)
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)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:236)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:82)
... 6 more
    Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:315)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:200)
at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:171)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234)
... 8 more
    Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:457)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:237)
... 20 more
    Caused by: java.lang.UnsupportedOperationException
at javax.faces.application.Application.getSearchExpressionHandler(Application.java:2001)
at javax.faces.application.ApplicationWrapper.getSearchExpressionHandler(ApplicationWrapper.java:815)
at com.sun.faces.config.processor.ApplicationConfigProcessor.setSearchExpressionHandler(ApplicationConfigProcessor.java:738)
at com.sun.faces.config.processor.ApplicationConfigProcessor.process(ApplicationConfigProcessor.java:382)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:155)
at com.sun.faces.config.processor.LifecycleConfigProcessor.process(LifecycleConfigProcessor.java:138)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:155)
at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:246)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:443)
... 21 more

    13:21:52,059 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "processmanagement-1.0-SNAPSHOT")]) - failure description: {
"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
    Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
    Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
    Caused by: java.lang.UnsupportedOperationException"},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}
    13:21:52,066 ERROR [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0021: Deploy of deployment "processmanagement-1.0-SNAPSHOT.war" was rolled back with the following failure message: 
    {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
Caused by: java.lang.UnsupportedOperationException"},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}

堆栈跟踪显示方法 javax.faces.application.Application.getSearchExpressionHandler 正在进入 'else' 块

    public SearchExpressionHandler getSearchExpressionHandler() {

    if (defaultApplication != null) {
        return defaultApplication.getSearchExpressionHandler();
    } else {
        throw new UnsupportedOperationException();
    }

    }

这显然意味着 defaultApplicatoin 为空。有什么理由吗?我是否遗漏了 omnifaces 2.6.1/jsf 2.3 的任何重要配置?

提前致谢!

这是 WildFly 中的错误。我已经举报了:http://issues.jboss.org/browse/WFLY-8815.

到目前为止,它的内置 WeldApplication 具有硬编码的 JSF 2.2 依赖项。它实际上应该从 JSF javax.faces.application.ApplicationWrapper 扩展而来,它已经预定义了所有默认的委托方法,例如 getSearchExpressionHandler(),但是 JSF 2.2-tied WeldApplication 没有那个,因此你例外面对。

OmniFaces 没有错,它只是一个触发器。对于具有自定义 javax.faces.application.Application 实现的任何其他以 JSF 为目标的库,您会遇到完全相同的问题。

如果将 JSF 降级回 2.2 不是一个选项,并且您没有耐心等待 WildFly 人员修复它,那么您可以如下修改 WildFly 修复其损坏的 WeldApplication

  1. 找到source code of org.jboss.as.jsf.injection.weld.WeldApplication (note: thus not org.jboss.weld.environment.servlet.jsf.WeldApplication which indeed has this bug already修复!这仅适用于 Tomcat).

  2. 调整 class 来自

    的签名
    public class WeldApplication extends ForwardingApplication {
    

    public class WeldApplication extends ApplicationWrapper {
    
  3. 替换构造函数中的第一行

    this.application = application;
    

    来自

    super(application);
    
  4. 删除此方法

    @Override
    protected Application delegate() {
        init();
        return application;
    }
    
  5. 替换两次出现的

    application.getExpressionFactory()
    

    来自

    getWrapped().getExpressionFactory()
    
  6. 编译它,你会得到两个class:WeldApplication.classWeldApplication$AdjustableELResolver.class

  7. 转到 WildFly 安装的 /modules/system/layers/base/org/jboss/as/jsf-injection/main 文件夹。

  8. 在那里解压 wildfly-jsf-injection-10.1.0.Final.jar

  9. 浏览并删除解压缩 JAR 的 /org/jboss/as/jsf/injection/weld 子文件夹中的所有三个 WeldApplication***.class 文件,并将两个新编译的文件放在那里。

  10. 将文件夹重新压缩到新的 wildfly-jsf-injection-10.1.0.Final.jar,覆盖旧的。

  11. 利润。