如何在Spring应用程序中使用Maven将JSF 2.2更新为JSF 2.3

时间:2017-05-15 09:13:50

标签: spring maven jsf jsf-2

我使用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           at com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.el.E​​LUtils.buildFacesResolver(ELUtils.java:242)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:484)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationImpl.performOneTimeELInitialization(ApplicationImpl.java:1404)~ [javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationImpl.getELResolver(ApplicationImpl.java:526)~ [javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:256)~ [javax.faces-2.3.0.jar:2.3.0]           at 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]           at java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0_111]           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_111]           at 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 ERROR 9936 --- [ost-startStop-1] oaccC [Tomcat]。[localhost]。[/]:将上下文初始化事件发送到类com的监听器实例的异常。 sun.faces.config.ConfigureListener

     

java.lang.RuntimeException:javax.faces.FacesException:无法找到CDI BeanManager           at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:315)〜[javax.faces-2.3.0.jar:2.3.0]           at 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]           at java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0_111]           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_111]           at 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           at com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.el.E​​LUtils.buildFacesResolver(ELUtils.java:242)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:484)〜[javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationImpl.performOneTimeELInitialization(ApplicationImpl.java:1404)~ [javax.faces-2.3.0.jar:2.3.0]           at com.sun.faces.application.ApplicationImpl.getELResolver(ApplicationImpl.java:526)~ [javax.faces-2.3.0.jar:2.3.0]           at 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或其他任何地方是否需要进行更多更改?

3 个答案:

答案 0 :(得分:7)

老问题,但对于仍然面临这个问题的人:要避免&#34;无法找到CDI BeanManager&#34;错误,重要的是,faces-config.xml版本 2.3而您的web.xml版本 {{1 }}!

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

4.0

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

答案 1 :(得分: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)在beans.xml

中创建WEB-INF
<?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>

答案 2 :(得分:0)

好吧,我的answear似乎与这个问题无关,但这是... 我恰好遇到了这种异常,这不是第一次。我在生产中有一个环境,在发展中又有一个环境。它们尽可能相同。我的环境是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设置中没有缺少此设置即可。