Tomcat 6下的JSF 2.0应用程序:"未配置任何工厂。"

时间:2012-07-24 15:07:57

标签: java tomcat maven jsf-2 maven-tomcat-plugin

我正在尝试在Tomcat 6网络服务器上使用Apache MyFaces 2.1.7运行JSF 2.0 webapp。该应用程序使用Tomahawk 1.1.11和表达式语言2.2(el-impl-2.2.jar)。为此,我将myfaces-api和myfaces-impl放入Tomcats lib文件夹,并将Tomcats el-api.jar交换为2.2变种。

当我调用应用程序的第一页时,我总是收到错误:

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>

javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:679)

我绝对拥有web.xml中提到的xml片段。我尝试调试代码,发现registeredFactoryNames第267行的javax.faces.FactoryFinder为空,导致错误。但我不明白为什么会这样。那里应该有什么,我该怎么做?

有趣的是,webapp使用嵌入式jetty 8完美运行。所以它必须是一些依赖性问题。

希望有更深入了解所有这些的人可以帮助我。

2 个答案:

答案 0 :(得分:2)

确定

我发现了问题。在类路径上两次使用myfaces-api.jar会导致错误。所以对我来说问题是我将myfaces-api.jar放在tomcat lib文件夹和webapp的WEB-INF / lib文件夹中。

在使用带有maven的嵌入式tomcat时,我在整个应用程序的依赖项中使用了myfaces-api.jar,并在tomcat6-maven-plugin的依赖项中使用了scope编译。我将范围从编译更改为在全局依赖关系部分中提供,并且它起作用。

答案 1 :(得分:1)

我认为只需在/ WEB-INF /文件夹下添加一个空的faces-config.xml文件即可解决,以指示应用程序使用JSF和MyFaces继续初始化步骤。有关详细信息,请参阅org.apache.myfaces.ee6.MyFacesContainerInitializer类。