【问题标题】:How to update JSF 2.2 to JSF 2.3 using Maven in a Spring Application如何在 Spring 应用程序中使用 Maven 将 JSF 2.2 更新到 JSF 2.3
【发布时间】:2017-05-15 09:13:49
【问题描述】:

我正在使用 MAVEN 并且已经将我的 pom.xml 依赖项更改为:

<dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.14</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.13</version>
        <scope>compile</scope>
        <optional>true</optional>
    </dependency>

到:

<dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.0</version>
    </dependency>

但现在我得到一个构建错误:

javax.faces.FacesException:找不到 CDI BeanManager 在 com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.el.E​​LUtils.buildFacesResolver(ELUtils.java:242) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:484) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationImpl.performOneTimeELInitialization(ApplicationImpl.java:1404) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationImpl.getELResolver(ApplicationImpl.java:526) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:256) ~[javax.faces-2.3.0.jar:2.3.0] 在 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4725) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] 在 java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]

2017-05-15 11:12:44.071 错误 9936 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]:向 com 类的侦听器实例发送上下文初始化事件的异常。 sun.faces.config.ConfigureListener

java.lang.RuntimeException: javax.faces.FacesException: 找不到 CDI BeanManager 在 com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:315) ~[javax.faces-2.3.0.jar:2.3.0] 在 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4725) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) [tomcat-embed-core-8.5.5.jar:8.5.5] 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] 在 java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] 原因:javax.faces.FacesException:找不到 CDI BeanManager 在 com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.el.E​​LUtils.buildFacesResolver(ELUtils.java:242) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:484) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationImpl.performOneTimeELInitialization(ApplicationImpl.java:1404) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.application.ApplicationImpl.getELResolver(ApplicationImpl.java:526) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:256) ~[javax.faces-2.3.0.jar:2.3.0]

我还将faces-config.xml 中的版本更新为2.3:

<faces-config 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/web-facesconfig_2_2.xsd"
          version="2.3">
<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    <el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
</application>

<factory>
    <exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>

pom.xml 或我的应用程序中的其他任何地方是否有更多更改?

【问题讨论】:

  • 您的问题标题“如何更新...”是解决问题的方法。请改进标题...完整的堆栈跟踪很可能包含原因...我在这里只看到 Spring 错误,与 JSF 无关
  • 感谢您的建议@Kukeltje .. 我更新了问题
  • 我猜在 faces-config.xml 中 xsi:schemaLocation 也应该更新到 2.3:xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd

标签: spring maven jsf jsf-2


【解决方案1】:

老问题,但对于仍然面临这个问题的人:为了避免“无法找到 CDI BeanManager”错误,重要的是您的 faces-config.xml 版本是 not 2.3 和您的 @987654324 @ 版本不是 4.0!

Mojarra 实现 ELUtils class 包含以下代码:

if (getFacesConfigXmlVersion(facesContext).equals("2.3") || getWebXmlVersion(facesContext).equals("4.0")) {
                throw new FacesException("Unable to find CDI BeanManager");
}

当使用较低版本时,它会跳过此检查,并使用 Spring DI 而不是 CDI。

【讨论】:

  • 我不明白为什么这段漂亮的小代码会在 GlassFish 的 JSF 实现中! jar 版本为 2.3,但如果在 Servlet 4.0 下使用它会引发异常?还是我理解错了?
  • 如果您使用@ManagedBean 注释,这是必需的。如果你使用@Named(你应该)你不会得到这个错误
【解决方案2】:
  1. 添加 CDI 和焊接依赖 pom.xml
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>
    
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.2.9.Final</version>
    </dependency>
    
  2. WEB-INF 中创建beans.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:weld="http://jboss.org/schema/weld/beans"
        xsi:schemaLocation="
        http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd
        http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
    
      <weld:scan>
        <weld:exclude name="org.springframework.data.jpa.repository.cdi.**" />
        <weld:exclude name="com.example.beans.**" />
      </weld:scan>
    </beans>
    

【讨论】:

    【解决方案3】:

    好吧,我的回答可能看起来与这个问题无关,但它是...... 我确实经历过这个例外,这不是第一次。我有一种生产环境和另一种开发环境。它们尽可能相同。我的环境是 glassfish 4.1.2,更新为使用 mojarra 2.3(我已经交换了 glassfish4/glassfish/modules/javax.faces.jar 文件)。我在一个 .jks 文件中有一些安全证书,这些信息非常重要,一个名为“-Djavax.net.ssl.trustStorePassword”的 jvm 设置,默认值为“changeit”。由于某种奇怪的原因,此设置在一次部署中消失了。我不知道为什么,但它发生了。我的结论是,这个缺失的设置在异常“javax.faces.FacesException:无法找到 CDI BeanManager”之前引发了一个异常,我无法诊断它。这是这两种环境之间的唯一区别。因此,如果您的应用程序抛出此异常并且它使用了一些 .jks 文件,只需验证您的 jvm 设置中没有缺少此设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 2013-04-12
      • 2021-02-26
      • 2016-12-25
      • 2020-08-31
      • 2014-04-18
      相关资源
      最近更新 更多