gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:47:18 24 4
gpt4 key购买 nike

对于我的应用,我使用的是 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 使用委托(delegate)器,所以结果是这个委托(delegate)器导致了问题。我需要做的就是让这个类实现 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>

最佳答案

在我的例子中,从我的 web.xml 中删除了以下行:

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

...是什么让错误消失了。

(正在修复纯 Tomcat 7 以与 JSF 一起工作。)

关于jsf - MyFaces 1.2 : java. lang.IllegalStateException 的应用程序错误:没有为此应用程序配置工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6436757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com