2

当文档(行)已插入 MongoDB 集合时,尝试让 EJB 通知我的 XHTML JSF 页面。

由于我之前的问题的答案,让 JSF 2.3 工作:

JSF 2.3 中的 f:websocket

然而,在将服务器端代码添加到我的 EJB 并尝试将我的 EAR 部署到 WildFly 12.0.0.Final 之后,我得到了 PushContext 的 java.lang.ClassNotFoundException:

Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class com.notifywell.ejb.FoodsCosmeticsMedicinesEJB with ClassLoader ModuleClassLoader for Module "deployment.NOTiFYwell.ear.NOTiFYwellJAR.jar" from Service Module Loader

    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: javax.faces.push.PushContext from [Module "deployment.NOTiFYwell.ear.NOTiFYwellJAR.jar" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:199)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
    ... 18 more

在 EJB 中使用:

@Inject
@Push
private PushContext push;

包含在:

jboss-jsf-api_2.3_spec-2.3.3.SP1.jar

当我添加@Inject@Push.

WildFly 12 和/或 JSF 2.3 中的 CDI 有任何问题吗?

4

1 回答 1

8

在 EJB 中使用:

@Inject
@Push

您永远不应该在 EJB 中使用面向前端的库。这样,您的 EJB 就变得与 JSF 前端紧密耦合,并且对于其他前端(例如 JAX-RS、JSP/Servlet 等)完全不可重用。

@Push文档甚至明确提到只在WAR 端注入它。

也可以看看:


将“jboss-jsf-api_2.3_spec-2.3.3.SP1.jar”添加到我部署的 EAR/JAR:

您永远不应该将重复的类添加到运行时类路径中。它只会混淆类加载器。目标运行时 (WildFly) 本身已经提供了特定的库。您不需要从部署开始提供它。

也可以看看:


WildFly 12 和/或 JSF 2.3 中的 CDI 有任何问题吗?

不适合我。OmniFaces 展示目前运行带有 JSF 2.3 的 WildFly 12,而 OmniFaces 对应的@Push工作正常。

当您打算在其上使用 JSF 2.3 时,您只需要记住明确指示 WildFly 12 使用。standalone-ee8.xml在 IDE 中使用时也是如此。在 Eclipse 中,创建服务器时,您可以在新建服务器向导的配置文件条目中指定它,默认为.standalone.xml

在此处输入图像描述

如果您仍然面临类加载问题,那只能意味着您以其他方式弄乱了运行时类路径。这可能有更多在目前提供的信息中不可见的原因。对于像您这样的初学者,在关于类路径问题的问题中没有立即提及类路径配置(因此表明对此一无所知),最好不要乱用运行时​​类路径(或“构建路径”和“库”正如在普通 IDE 中所调用的那样),直到您了解它为止。默认情况下,Java EE 已经提供了开箱即用的所有内容,完全不需要调整项目中的库。

将所有内容保留为默认值,注入@PushWAR 而不是 EJB,并告诉 WildFly 在 EE8 模式下运行,一切都会顺利进行。

也可以看看:

于 2018-04-17T06:39:15.727 回答