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

Igo*_*gor 6 jsf tomcat myfaces

对于我的应用程序,我使用的是Tomcat 6.0.xMojarra 1.2_04 JSF实现.它运行正常,我想现在切换到JSF的MyFaces 1.2_10 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)
...
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

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

编辑:

我能够解决问题.因为我正在使用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>
Run Code Online (Sandbox Code Playgroud)

这是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...
}
Run Code Online (Sandbox Code Playgroud)

编辑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>
Run Code Online (Sandbox Code Playgroud)

小智 5

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

<load-on-startup>1</load-on-startup>
Run Code Online (Sandbox Code Playgroud)

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

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