Wildfly 以错误开头。 javax.faces.FacesException:找不到 CDI BeanManager

Posted

技术标签:

【中文标题】Wildfly 以错误开头。 javax.faces.FacesException:找不到 CDI BeanManager【英文标题】:Wildfly starts with error. javax.faces.FacesException: Unable to find CDI BeanManager 【发布时间】:2020-04-23 17:39:21 【问题描述】:

我已经使用 WildFly 18,jdk-13.0.1 在 Eclipse 中编写了我的第一个 JSF hello world 程序。 ,Windows 10。

Wildfly 主页和管理控制台工作查找,但从 url http://localhost:8080/jsf1/faces/WEB-INF/helloworld.xhtml 执行程序时它给出 404 - Not Found 错误。我在 url http://localhost:8080/jsf1 上遇到同样的错误

这是 web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>jsf1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
</web-app>

以下是wildfly服务器日志

2020-01-06 10:59:19,677 INFO  [org.jboss.as.patching] (MSC service thread 1-2) WFLYPAT0050: WildFly Full cumulative patch ID is: base, one-off patches include: none
2020-01-06 10:59:19,694 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-6) WFLYDM0111: Keystore C:\Program Files\wildfly-18.0.1.Final\standalone\configuration\application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
2020-01-06 10:59:19,702 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Program Files\wildfly-18.0.1.Final\standalone\deployments
2020-01-06 10:59:19,723 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "jsf2.war" (runtime-name: "jsf2.war")
2020-01-06 10:59:19,720 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "jsf1.war" (runtime-name: "jsf1.war")
2020-01-06 10:59:19,827 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
2020-01-06 10:59:20,856 INFO  [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.3.0.Final (Apache CXF 3.3.3) 
2020-01-06 10:59:25,045 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Infinity Minus ONE +2' 9.4.16.Final
2020-01-06 10:59:25,635 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 77) WFLYCLINF0002: Started client-mappings cache from ejb container
2020-01-06 10:59:26,604 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 80) Initializing Mojarra 2.3.9.SP04 for context '/jsf1'
2020-01-06 10:59:26,610 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 78) Initializing Mojarra 2.3.9.SP04 for context '/jsf2'
2020-01-06 10:59:27,168 ERROR [stderr] (ServerService Thread Pool -- 80) javax.faces.FacesException: Unable to find CDI BeanManager

2020-01-06 10:59:27,169 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.applicationimpl.Version.isJsf23(Version.java:62)

2020-01-06 10:59:27,169 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.applicationimpl.ExpressionLanguage.addELResolver(ExpressionLanguage.java:136)

2020-01-06 10:59:27,170 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.ApplicationImpl.addELResolver(ApplicationImpl.java:221)

2020-01-06 10:59:27,170 ERROR [stderr] (ServerService Thread Pool -- 80)    at org.jboss.as.jsf-injection//org.jboss.as.jsf.injection.weld.WeldApplication.<init>(WeldApplication.java:60)

2020-01-06 10:59:27,171 ERROR [stderr] (ServerService Thread Pool -- 80)    at org.jboss.as.jsf-injection//org.jboss.as.jsf.injection.weld.WeldApplicationFactory.getApplication(WeldApplicationFactory.java:52)

2020-01-06 10:59:27,171 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:61)

2020-01-06 10:59:27,172 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:109)

2020-01-06 10:59:27,173 ERROR [stderr] (ServerService Thread Pool -- 80)    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.lifecycle.ClientWindowFactoryImpl.<init>(ClientWindowFactoryImpl.java:39)

2020-01-06 10:59:27,173 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

2020-01-06 10:59:27,174 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

2020-01-06 10:59:27,174 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

2020-01-06 10:59:27,174 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

2020-01-06 10:59:27,175 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)

2020-01-06 10:59:27,175 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)

2020-01-06 10:59:27,176 ERROR [stderr] (ServerService Thread Pool -- 80)    at java.base/java.lang.Class.newInstance(Class.java:591)

日志的最后几行

Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:357)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:205)
    ... 21 more
Caused by: java.lang.NullPointerException
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.facelets.impl.DefaultResourceResolver.resolveUrl(DefaultResourceResolver.java:40)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.facelets.impl.DefaultFaceletFactory.init(DefaultFaceletFactory.java:129)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.ApplicationAssociate.createFaceletFactory(ApplicationAssociate.java:849)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.ApplicationAssociate.initializeFacelets(ApplicationAssociate.java:342)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.application.ApplicationAssociate.getCompiler(ApplicationAssociate.java:420)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.config.processor.FaceletTaglibConfigProcessor.process(FaceletTaglibConfigProcessor.java:217)
    at com.sun.jsf-impl@2.3.9.SP04//com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:341)
    ... 22 more

2020-01-06 10:59:28,236 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "jsf1.war")]) - failure description: "WFLYCTL0080: Failed services" => "jboss.deployment.unit.\"jsf1.war\".undertow-deployment" => "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.NullPointerException"
2020-01-06 10:59:28,466 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "jsf2.war")]) - failure description: "WFLYCTL0080: Failed services" => "jboss.deployment.unit.\"jsf2.war\".undertow-deployment" => "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.NullPointerException"
2020-01-06 10:59:28,518 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 44) WFLYSRV0010: Deployed "jsf2.war" (runtime-name : "jsf2.war")
2020-01-06 10:59:28,519 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 44) WFLYSRV0010: Deployed "jsf1.war" (runtime-name : "jsf1.war")
2020-01-06 10:59:28,521 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."jsf2.war".undertow-deployment: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
      service jboss.deployment.unit."jsf1.war".undertow-deployment: java.lang.RuntimeException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! null
WFLYCTL0448: 2 additional services are down due to their dependencies being missing or failed
2020-01-06 10:59:28,735 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
2020-01-06 10:59:28,745 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
2020-01-06 10:59:28,745 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
2020-01-06 10:59:28,745 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 18.0.1.Final (WildFly Core 10.0.3.Final) started (with errors) in 29279ms - Started 496 of 731 services (6 services failed or missing dependencies, 379 services are lazy, passive or on-demand)

文件夹树:

【问题讨论】:

你的 pom.xml 和文件/文件夹树是什么样的? /jsf1/faces/WEB-INF/helloworld.xhtml 是一个奇怪的请求路径顺便说一句。 是的,两个404都可以解释,与启动问题没有任何关系,除非完全部署失败,这是你的情况,那么这是很正常的。你有没有在你的战争中包含 jsf(这就是 Selaron 最有可能从 pom.xml 中推断出来的) 好的,您是否尝试在搜索引擎中发布 "javax.faces.FacesException: Unable to find CDI BeanManager" 您的xhtml 文件应该在您的WebContent 目录中,而不是WEB-INFWEB-INF 没有公开为 Web 目录,绝对不应该公开。如果这被暴露了,那么您的所有配置文件也会被暴露。 您能否检查一下您的项目中是否有“旧”@ManagedBean 注释?我已经很长时间没有使用它们了,但是在调查***.com/questions/59667297/… 时,我偶然遇到了同样的错误,并认为注释与它有关。当我不使用@ManagedBean@Named(我已经这样做了很长时间)时,我在使用 servlet 4.0 和 jsf 2.3 规范时不会收到此错误 【参考方案1】:

我在WEB-INF 目录中添加了beans.xml 文件,内容如下,错误消失了。最后,我可以在“Dynamic Web Module 4.0 版”和“Java Server Faces 2.3 版”中运行我的 hello world 程序。

beans.xml 内容

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

</beans>

【讨论】:

我正在学习一个没有 beans.xml 文件的教程,服务器是 Glassfish,但我的服务器实际上是 Wildfly,这个需要 beans.xml 文件!有趣的是,两个 JEE 兼容服务器但基本配置不同。感谢您提供此解决方案。【参考方案2】:

我通过创建一个新项目并将“Dynamic Web Module version to 3.1”和“Java Server Faces version to 2.2”修复了这个错误。以前,它们分别设置为版本 4 和 2.3。

【讨论】:

对我来说这仍然是一种解决方法。您也可以通过搜索在此解决方案中遇到的错误来找到其中一个问答,但我发现您无法真正激活 2.3 很奇怪......我会看看我是否可以在下周末进行调查 您能否检查一下您的项目中是否有“旧”@ManagedBean 注释?我已经很长时间没有使用它们了,但是在调查***.com/questions/59667297/… 时,我偶然遇到了同样的错误,并认为注释与它有关。当我不使用@ManagedBean@Named(我已经这样做了很长时间)时,我在使用 servlet 4.0 和 jsf 2.3 规范时不会收到此错误 @Kukeltje 我没有使用托管 bean,它只包含两个 .xhtml 文件,没有别的。我完全按照本教程 youtube.com/watch?v=SZ2kxtbFONY 编写了这个 JSF hello world 示例,唯一的区别是我选择了 JSF 2.3 和动态 Web 模块版本 4。它不起作用,所以我将它们的版本设置为 2.2 和 3.1。跨度> 让我明天用请求参数试试。您能否同时尝试使用 jsf 托管 bean 并将其更改为 cdi 托管 bean 以查看它是否有所不同(使用 4 和 2.3 作为版本) 查看 jsf.zeef.com 以获得良好的 2.3 教程。曾经的 youtube 往往不是最好的。对于 jsf 2.3,您应该使用 cdi 托管 bean 而不是 jsf 的。现在你也明白为什么minimal reproducible example'sre 相关

以上是关于Wildfly 以错误开头。 javax.faces.FacesException:找不到 CDI BeanManager的主要内容,如果未能解决你的问题,请参考以下文章

Wildfly 10 中的 Hibernate 4.3 支持

如何配置wildfly以使用EclipseLink?

找不到工厂:javax.faces.context.FacesContextFactory

Wildfly 8 似乎没有记录 -verbose:class 数据?

添加用户时出现 WildFly 错误

如何修复 Wildfly 中的“15 秒后无法获取锁”错误