对于我的应用程序,我使用Tomcat 6.0.x和Mojarra 1.2_04JSF实现。它工作得很好,只是我现在想切换到JSF的MyFaces1.2_10impl。
在部署我的应用程序期间,会出现以下错误:
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使用delegator,因此发现问题是由该delegator引起的。我所需要做的就是让这个类实现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一起工作。)