简体   繁体   English

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

[英]How to update JSF 2.2 to JSF 2.3 using Maven in a Spring Application

I'm using MAVEN and already changed my pom.xml dependencies from:我正在使用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>

to:到:

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

but now I get a build error:但现在我收到一个构建错误:

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] 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. javax.faces.FacesException:无法在 com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312) ~[javax.faces-2.3.0.jar:2.3.0] 在 com.sun 找到 CDI BeanManager .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] 在 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] 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] 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 ERROR 9936 --- [ost-startStop-1] oaccC[Tomcat].[localhost].[/] : Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener 2017-05-15 11:12:44.071 错误 9936 --- [ost-startStop-1] oaccC[Tomcat].[localhost].[/] :异常发送上下文初始化事件到类 com.sun.faces 的侦听器实例.config.ConfigureListener

java.lang.RuntimeException: javax.faces.FacesException: Unable to find 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] 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.ThreadPo java.lang.RuntimeException: javax.faces.FacesException: 无法在 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.ThreadPo olExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] Caused by: 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] olExecutor$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:无法在 com.sun.faces.el.E​​LUtils.tryAddCDIELResolver(ELUtils.java:312) ~[javax.faces-2.3.0.jar:2.3.0] 处找到 CDI BeanManager,位于 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] 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 my faces-config.xml to 2.3:我还将我的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>

Are there more changes to make in the pom.xml or anywhere else in my application?pom.xml或我的应用程序中的其他任何地方是否有更多更改?

Old question, but for people still facing this problem: To avoid the "Unable to find CDI BeanManager" error, it's important that your faces-config.xml version is not 2.3 and your web.xml version is not 4.0 !老问题,但对于仍然面临这个问题的人:为了避免“无法找到 CDI BeanManager”错误,重要的是您的faces-config.xml版本不是2.3并且您的web.xml版本不是4.0

The Mojarra implementation ELUtils class contains the following nice bit of code: Mojarra 实现ELUtils 类包含以下代码:

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.使用较低版本时,它会跳过此检查,并使用 Spring DI 而不是 CDI。

  1. Add CDI and weld dependency pom.xml添加 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. create beans.xml in WEB-INFWEB-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>

Well, my answear may appears unrelated to this question, but it is... I experienced exactly this exception, and it was not the first time.好吧,我的回答可能看起来与这个问题无关,但它是......我经历了这个例外,这不是第一次。 I have one enviroment in production and another, for development.我有一个生产环境和另一个开发环境。 They are identical, as much as possible.它们尽可能相同。 My environment is glassfish 4.1.2, updated to use mojarra 2.3 (I've swapped the glassfish4/glassfish/modules/javax.faces.jar file).我的环境是 glassfish 4.1.2,更新为使用 mojarra 2.3(我已经交换了 glassfish4/glassfish/modules/javax.faces.jar 文件)。 I have some secure certificates in one .jks file, and this information is very important, one jvm setting called "-Djavax.net.ssl.trustStorePassword", with default value "changeit".我在一个 .jks 文件中有一些安全证书,这个信息非常重要,一个名为“-Djavax.net.ssl.trustStorePassword”的 jvm 设置,默认值为“changeit”。 For some strange reason this setting disappeared in one deploy.出于某种奇怪的原因,此设置在一次部署中消失了。 I don't know why, but it happened.我不知道为什么,但它发生了。 My conclusion is that this missing setting had thrown one exception BEFORE the exception "javax.faces.FacesException: Unable to find CDI BeanManager" and I could not diagnose it.我的结论是,这个缺失的设置在异常“javax.faces.FacesException: Unable to find CDI BeanManager”之前抛出了一个异常,我无法诊断它。 That was the only differece between this two environments.这是这两种环境之间的唯一区别。 So, if your application is throwing this exception and it uses some .jks file, just verify that this setting is not missing in your jvm settings.因此,如果您的应用程序抛出此异常并且它使用了一些 .jks 文件,只需验证您的 jvm 设置中没有缺少此设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM