Grails 插件项目中的 jsf2“...backup for factory javax.faces.context.FacesContextFactory”出错

Posted

技术标签:

【中文标题】Grails 插件项目中的 jsf2“...backup for factory javax.faces.context.FacesContextFactory”出错【英文标题】:Getting error with jsf2 "...backup for factory javax.faces.context.FacesContextFactory" in Grails plugin project 【发布时间】:2012-04-18 15:51:42 【问题描述】:

我在开发模式下运行 Grails 2.01 和 Tomcat(普通 STS 开发人员下载)。

我尝试运行 jsf 插件,但它在 Grails 2 中无法运行。

因此,为了指导我,我尝试构建自己的本地插件,将其构建为原生 v2 插件,并在途中了解插件项目。我一直在(缓慢地)解构 Grails jsf2 插件,并以艰难的方式一点一点地重建它,边走边学。

我的问题如下 - 我在本地构建了我的插件 - 称之为'wwjsf'。

我已经完成了 doWithWebDescriptor 关闭 - 但是当我运行插件时,我得到一个错误 - 服务器不会呈现 .xhtml 文件 - 任何此类请求都会给出相同的错误。

我已将最新的 Mojarra jsf 2.1.7 api/impl 文件包含到我的项目构建路径中 - 这是 Grails 2.01 中嵌入的默认 Tomcat 的错误。

Message: Could not find backup for factory javax.faces.context.FacesContextFactory.
Line | Method
->> 1008 | getFactory in javax.faces.FactoryFinder$FactoryManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    343 | getFactory in javax.faces.FactoryFinder
|    302 | init . . . in javax.faces.webapp.FacesServlet
|    303 | innerRun   in java.util.concurrent.FutureTask$Sync
|    138 | run . . .  in java.util.concurrent.FutureTask
|    886 | runTask    in java.util.concurrent.ThreadPoolExecutor$Worker
|    908 | run . . .  in     ''
^    662 | run        in java.lang.Thread
| Error 2012-04-04 18:32:55,748 [pool-6-thread-1] ERROR [localhost].[/wwjsf]  - Servlet    /wwjsf threw load() exception
Message: Could not find backup for factory javax.faces.context.FacesContextFactory.
Line | Method
->> 1008 | getFactory in javax.faces.FactoryFinder$FactoryManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    343 | getFactory in javax.faces.FactoryFinder
|    302 | init . . . in javax.faces.webapp.FacesServlet
|    303 | innerRun   in java.util.concurrent.FutureTask$Sync
|    138 | run . . .  in java.util.concurrent.FutureTask
|    886 | runTask    in java.util.concurrent.ThreadPoolExecutor$Worker
|    908 | run . . .  in     ''
^    662 | run        in java.lang.Thread
| Server running. Browse to http://localhost:8080/wwjsf

我已经完成了在闭包中最终确定的 web.xml 的转储,以便查看。我在 Google 上查找了错误,它说你必须设置 facesConfigureListener - 我有,我已经检查了 xml 中的 faces 服务器元素,我认为它看起来不错。

此外,我在 WEB-INF 下放了一个空 faces-config.xml(我会担心如何在稍后使用该插件的项目中创建它),正如一些 Google 警告所说,我必须将 jsf 文件放在 WEB-INF/lib 目录中 - 我手动创建了该 /lib 并将我的 jsf 2.1.7 api/impl jar 复制到其中以及用于皮带和大括号。

如何消除嵌入式 Tomcat 服务器中的这个错误?

最终的 web.xml 配置如下:

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance" 
    metadata-complete="true" version="2.5" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   <display-name>/wwjsf-development-null</display-name>
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
   </context-param>
   <context-param>
     <param-name>com.sun.faces.validateXml</param-name>
     <param-value>false</param-value>
   </context-param>
   <context-param>
      <param-name>com.sun.faces.verifyObjects</param-name>
      <param-value>false</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.application.CONFIG_FILES</param-name>
      <param-value>C:\Users\802518659\Documents\grails-workspace\wwjsf\web-app\WEB-INF\faces-config.xml</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>server</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
      <param-value>com.softwood.grails.jsf.facelets.GrailsResourceResolver</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.PROJECT_STAGE</param-name>
      <param-value>Production</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
      <param-value>.xhtml</param-value>
   </context-param>
   <context-param>
      <param-name>javax.faces.REFRESH_PERIOD</param-name>
      <param-value>0</param-value>
   </context-param>
   <context-param>
      <param-name>webAppRootKey</param-name>
      <param-value>wwjsf-development-null</param-value>
   </context-param>
   <filter>
     <filter-name>sitemesh</filter-name>
     <filter-class>org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter</filter-class>
   </filter>
   <filter>
     <filter-name>charEncodingFilter</filter-name>
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
     <init-param>
        <param-name>targetBeanName</param-name>
        <param-value>characterEncodingFilter</param-value>
     </init-param>
     <init-param>
        <param-name>targetFilterLifecycle</param-name>
        <param-value>true</param-value>
     </init-param>
   </filter>
   <filter>
      <filter-name>urlMapping</filter-name>
      <filter-class>org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter</filter-class>
   </filter>
   <filter>
     <filter-name>hiddenHttpMethod</filter-name>
     <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
   </filter>
   <filter>
      <filter-name>grailsWebRequest</filter-name>
      <filter-class>org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter</filter-class>
   </filter>
   <filter-mapping>
      <filter-name>charEncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
   <filter-mapping>
      <filter-name>hiddenHttpMethod</filter-name>
      <url-pattern>/*</url-pattern>
     <dispatcher>FORWARD</dispatcher>
     <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>grailsWebRequest</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>ERROR</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>sitemesh</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>ERROR</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>urlMapping</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <listener>
      <listener-class>org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener</listener-class>
   </listener>
   <listener>
      <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener</listener-class>
    </listener>
  <servlet>
   <servlet-name>H2Console</servlet-name>
   <servlet-class>org.h2.server.web.WebServlet</servlet-class>
   <init-param>
    <param-name>-webAllowOthers</param-name>
    <param-value>true</param-value>
   </init-param>
   <load-on-startup>2</load-on-startup>
  </servlet>
  <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>H2Console</servlet-name>
    <url-pattern>/dbconsole/*</url-pattern>
    </servlet-mapping>
  <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
     <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>grails</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>gsp</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.pages.GroovyPagesServlet</servlet-class>
    <init-param>
    <description>
            Allows developers to view the intermediate source code, when they pass
            a spillGroovy argument in the URL.
            </description>
    <param-name>showSource</param-name>
    <param-value>1</param-value>
    </init-param>
  </servlet>
  <servlet>
     <servlet-name>grails-errorhandler</servlet-name>
     <servlet-class>org.codehaus.groovy.grails.web.servlet.ErrorHandlingServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>gsp</servlet-name>
    <url-pattern>*.gsp</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
   <servlet-name>grails-errorhandler</servlet-name>
   <url-pattern>/grails-errorhandler</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
     <servlet-name>grails</servlet-name>
     <url-pattern>*.dispatch</url-pattern>
  </servlet-mapping>
  <welcome-file-list>

    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.gsp</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>500</error-code>
    <location>/grails-errorhandler</location>
 </error-page>
 <jsp-config>
    <taglib>
        <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
        <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
    </taglib>
       <taglib>
           <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
           <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://www.springframework.org/tags</taglib-uri>
            <taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://grails.codehaus.org/tags</taglib-uri>
            <taglib-location>/WEB-INF/tld/grails.tld</taglib-location>
        </taglib>
    </jsp-config>
 </web-app>

【问题讨论】:

【参考方案1】:

当我遇到这个错误时(我使用 maven 和嵌入式码头以及 spring 和 jsf2),我在 web.xml 上添加了这个

 <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class> 
    </listener>

错误消失了。

【讨论】:

感谢先生的精彩回答。但是为什么会这样呢?这个解决方案是如何工作的?

以上是关于Grails 插件项目中的 jsf2“...backup for factory javax.faces.context.FacesContextFactory”出错的主要内容,如果未能解决你的问题,请参考以下文章

从 Grails 中的 Cobertura 报告中排除插件

Grails 中的邮件插件

在 Grails 中跨多个插件共享身份验证

Grails:如何引用位于已安装插件中的资源?

GORM 无法实现插件中的域类是 GORM 类

CSS 文件中的 URL 被 Grails 资源插件 1.2.7 破坏