MyFaces 1.2的应用程序错误:java.lang.IllegalStateException:没有为此应用程序配置的工厂

时间:2011-06-22 08:05:21

标签: jsf tomcat myfaces

对于我的应用,我使用 Tomcat 6.0.x Mojarra 1.2_04 JSF实现。 它工作正常,我想现在切换到 MyFaces 1.2_10 的JSF impl。

在部署我的应用程序期间,出现以下错误:

ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myApp]] StandardWrapper.Throwable
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:106)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:137)
    at org.apache.myfaces.webapp.MyFacesServlet.init(MyFacesServlet.java:113)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
...

以下是我的web.xml配置的一部分:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
        <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    ...
    <listener>
         <listener- class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

有没有人遇到过类似的错误,我该怎么做才能修复它?感谢名单!

修改

我能够解决问题。由于我正在使用 FacesServlet 的委托人,事实证明这个委托人造成了问题。 我需要做的就是使这个类实现 DelegatedFacesServlet ,并且我已经删除了 org.apache.myfaces.webapp.StartupServletContextListener 。这是我的web.xml现在:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
        <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Faces Servlet Delegator</servlet-name>
        <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet Delegator</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

这里是 FacesServletDelegator

public class PLMFacesServlet extends HttpServlet implements DelegatedFacesServlet {

    private MyFacesServlet delegate;

    public final void init(ServletConfig servletConfig) throws ServletException {
        delegate = new MyFacesServlet();
        delegate.init(servletConfig);
    }

    public final void destroy() {
        delegate.destroy();
    }

    public final ServletConfig getServletConfig() {
        return delegate.getServletConfig();
    }

    public final String getServletInfo() {
        return delegate.getServletInfo();
    }

    public final void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {

       try {
           delegate.service(request, response);
       } catch(Exception e) {}
    }
    // some other code...
}

编辑2

按照 BalusC 的建议,我编辑了 web.xml ,这是最终版本:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet Delegator</servlet-name>
    <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet Delegator</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

1 个答案:

答案 0 :(得分:5)

就我而言,从我的web.xml中删除以下行:

<load-on-startup>1</load-on-startup>

...是错误消失的原因。

(修复了纯粹的Tomcat 7以与JSF一起工作。)