How to upgrade JSF 2.2 to JSF 2.3 using Maven in Spring application

I am using MAVEN

and have already changed my dependencies pom.xml

from:

<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>

      

in

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

      

but now I am getting build error:

javax.faces.FacesException: Cannot find CDI BeanManager on com.sun.faces.el.ELUtils.tryAddCDIELResolver (ELUtils.java:312) ~ [javax.faces-2.3.0.jar: 2.3.0] on com.sun. faces.el.ELUtils.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] at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5189) [tomcat-embed -core-8.5.5.jar: 8.5.5] at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150) [tomcat-embed-core-8.5.5.jar: 8.5.5] on org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1403) [tomcat-embed-core-8.5.5.jar: 8.5.5] at 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] in java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617) [na: 1.8.0_111] at 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]. [/]: Prevent dispatch of context of an initialized event to a listener instance of com. sun.faces.config.ConfigureListener

java.lang.RuntimeException: javax.faces.FacesException: Unable to find CDI BeanManager in 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] at org.apache.catalina.core.StandardContext.startInternal ( StandardContext.java:5189) [tomcat-embed-core-8.5.5.jar: 8.5.5] at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150) [tomcat-embed-core-8.5 .5.jar: 8.5.5] at org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1403) [tomcat-embed-core-8.5.5.jar: 8.5.5] at 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] at java.lang.Thread.run (Thread.java:745) [na: 1.8.0_111] Reason: javax.faces.FacesException: Unable to find CDI BeanManager at com.sun.faces.el.ELUtils.tryAddCDIELResolver (ELUtils.java:312) ~ [javax.faces-2.3.0.jar: 2.3.0] at com.sun. faces.el.ELUtils.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]

I also updated the version in mine faces-config.xml

to 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>

      

Are there more changes to pom.xml

or elsewhere in my application?

+3


source to share


3 answers


An old question, but for people who still face this problem: in order to avoid the error "Cannot find CDI BeanManager" it is important that your version of the face is faces-config.xml

not 2.3

and yours web.xml

is not 4.0

!

Class ELUtils implementation Mojarra contains the following nice snippet of code:



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

      

When using lower versions, it skips this check and works with Spring DI instead of CDI.

+5


source


1) Add CDI and Weld ID 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) create beans.xml

inWEB-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


source


Well, my answer may seem unrelated to this question, but this ... I experienced exactly this exception and it was not the first time. I have one environment for production and another for development. They are as identical as possible. My environment is glassfish 4.1.2, updated to use mojarra 2.3 (I swapped glassfish4 / glassfish / modules / javax.faces.jar). I have multiple secure certificates in one .jks file and this information is very important, one jvm parameter is called "-Djavax.net.ssl.trustStorePassword" with default value "changeit". For some strange reason, this setting disappeared in one deployment. I don't know why, but it happened. I concluded that this missing parameter threw one exception before the "javax.faces.FacesException":cannot find CDI BeanManager "and I was unable to diagnose it. That was the only difference between the two environments. So if your application throws this exception and uses some kind of .jks file, just make sure this parameter is not omitted in jvm settings ...

0


source







All Articles