异常找不到工厂:javax.faces.application.ApplicationFactory

Posted

技术标签:

【中文标题】异常找不到工厂:javax.faces.application.ApplicationFactory【英文标题】:Exception could not find Factory: javax.faces.application.ApplicationFactory 【发布时间】:2012-10-12 11:03:36 【问题描述】:

我正在使用 JSF 2.0 Apache MyFaces、TomCat 7.0 和 primefaces 3.4.1,

在运行我的应用时,我遇到了这个异常

 SEVERE: Exception sending context initialized event to listener instance of class org.apache.myfaces.webapp.StartupServletContextListener java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:851)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:309)
    at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:131)
    at org.apache.myfaces.context.servlet.FacesContextImplBase.getELContext(FacesContextImplBase.java:180)
    at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1456)
    at org.apache.myfaces.webapp.AbstractFacesInitializer._createFacesContext(AbstractFacesInitializer.java:391)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initStartupFacesContext(AbstractFacesInitializer.java:363)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:105)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这里是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Capitulo2</display-name>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <filter>
    <filter-name>conexaoFilter</filter-name>
    <filter-class>financeiro.filter.ConexaoHibernateFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>conexaoFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
  </filter-mapping>
  <resource-ref>
    <description>DataSource financeirodb</description>
    <res-ref-name>jdbc/financeirodb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml
</param-value>
  </context-param>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>

</web-app>

我已经阅读了一些关于同一异常的主题,但建议的所有解决方案都已实施。

有什么新想法吗??

【问题讨论】:

【参考方案1】:

您似乎在一个 Web 应用中混合了不同的 JSF 实现 Mojarra 和 MyFaces。

您的环境描述和堆栈跟踪确认您正在使用 MyFaces,但您在 web.xml 中有以下特定于 Mojarra 的侦听器条目:

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

这是不对的。你应该删除它。它在侦听器类上没有ClassNotFoundException 的情况下成功初始化,这也表明您实际上 Mojarra 特定的 JAR,例如 javax.faces.jarjsf-impl.jarjsf-api.jar 在您的 web 应用程序的运行时类路径也是如此。使用 MyFaces 时,您应该删除它们并坚持使用 myfaces-*.jar

【讨论】:

以上是关于异常找不到工厂:javax.faces.application.ApplicationFactory的主要内容,如果未能解决你的问题,请参考以下文章

PHPUnit测试找不到工厂

Spring JPA - 找不到实体管理器工厂,为啥?

找不到工厂:javax.faces.context.FacesContextFactory

java.lang.IllegalStateException:找不到工厂 javax.faces.context.FacesContextFactory 的备份

java.lang.IllegalStateException:找不到工厂 javax.faces.application.ApplicationFactory 的备份

java.lang.IllegalStateException:找不到工厂javax.faces.context.FacesContextFactory的备份