我创建了我的hello world JSF项目,但是当我部署到Tomcat 7时,我得到这个例外:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory. at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135) at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379) at javax.faces.webapp.FacesServlet.init(FacesServlet.java:350) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
我已将这些JAR添加到我的项目中:
> jstl-1.2.jar
> javax.faces-api-2.2.jar
这是怎么造成的,我该如何解决呢?
解决方法
异常基本上告诉它找不到JSF实现.
I had added this jars to my project :
jstl-1.2.jar
andjavax.faces-api-2.2.jar
javax.faces-api-2.2.jar是不对的.有两个问题:
>这是“蓝图”API JAR,意图用于JSF实现者,如Mojarra和MyFaces.
>你忘记了JSF实现JAR.
如果您想使用Mojarra,则可以按照download page的说明安装Mojarra的方法有两种:
>一个JAR:javax.faces-2.x.x.jar
>或者两个JAR:jsf-api-2.x.x.jar
和jsf-impl-2.x.x.jar
,其中版本号必须完全匹配.
摆脱那个javax.faces-api-2.2.jar并将正确的JAR放在/ WEB-INF / lib中,这个异常应该消失.到目前为止,Mojarra 2.2.8是最新版本,一个JAR比两个松散的JAR更干净,所以去下载javax-faces-2.2.8.jar
来替换错误的JAR.