WildFly 12.0.0.Final JSF 2.3& f:websocket - 类加载器问题

时间:2018-04-16 14:35:00

标签: wildfly cdi weld jboss-weld jsf-2.3

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

由于我之前的问题的答案得到了JSF 2.3的工作:

f:websocket in JSF 2.3

然而,在将服务器端代码添加到我的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有任何问题吗?

1 个答案:

答案 0 :(得分:7)

  EJB中使用的

@Inject
@Push

您永远不应该在EJB中使用前端目标库。这样,您的EJB就变得紧密耦合到JSF前端,并且对于其他前端(如JAX-RS,JSP / Servlet等)完全无法使用。

@Push文档甚至explicitly提到仅在WAR端注入它。

另见:

  

添加&#39; jboss-jsf-api_2.3_spec-2.3.3.SP1.jar&#39;到我部署的EAR / JAR:

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

另见:

  

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

不适合我。 The OmniFaces showcase目前使用JSF 2.3运行WildFly 12,@Push的OmniFaces对应运行正常。

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

enter image description here

如果您仍然面临类加载问题,那么它只能意味着您以其他方式搞砸了运行时类路径。这可能有更多原因,这些原因在目前提供的信息中是看不到的。对于像你一样没有在类路径故障的问题中立即提及类路径配置的启动器(并因此表明对它的无知),最好不要乱用运行时​​类路径(或#&#) 34;构建路径&#34;和#34;库&#34;在普通IDE中调用),直到你理解它为止。 Java EE默认情况下已经提供了所有功能,绝对不需要来调整项目中的库。

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

另见: