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

发布于 2024-11-16 11:57:56 字数 4953 浏览 4 评论 0原文

对于我的应用程序,我使用 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)
...

这是我的 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 委托程序,因此事实证明该委托程序导致了问题。 我需要做的就是让这个类实现DelegateFacesServlet,并且我已经删除了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。 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>

For my app I'm using Tomcat 6.0.x and Mojarra 1.2_04 JSF implementation.
It works fine, just I would like to switch now to MyFaces 1.2_10 impl of JSF.

During the deployment of my app a get the following error:

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

Here is part of my web.xml configuration:

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

Has anyone experienced similar error, and what should I do i order to fix it? Thanx!

EDIT:

I was able to fix the problem. Since I am using delegator for FacesServlet, it turned out that this delegator was causing the problem.
All I needed to do is to make this class implement DelegatedFacesServlet, and I've removed org.apache.myfaces.webapp.StartupServletContextListener. Here is my web.xml now:

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

and here is 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...
}

EDIT 2:

Following BalusC advice, I've edited my web.xml a bit, here is the final version:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-11-23 11:57:56

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

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

...使错误消失。

(正在修复纯 Tomcat 7 以与 JSF 配合使用。)

In my case, the removal of the following line from my web.xml:

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

...was what made the error disappear.

(Was fixing up a pure Tomcat 7 to work with JSF.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文