could not find Factory: javax.faces.context.FacesContextFactory

♀尐吖头ヾ 提交于 2019-11-27 01:01:18

This listener is since JSF 1.x supposed to be automatically registered by the jsf_core.tld tag library definition file. You can find it in the /META-INF folder of the JSF implementation JAR file. In case of Mojarra 2.1.3 (which you seem to be using according the logs), the listener is registered as follows from line 80 and on:

<!-- ============== Configuration Listener ============== -->

<!--
      This ServletContextListener initializes the runtime environment
      of the JavaServer Faces Reference Implementation when a web
      application including it is initialized by the container.
-->
<listener>
   <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>      

However, this is apparently not been picked up properly by Jetty. I've also read somewhere that when the FacesServlet is been initialized before the TLD file is been processed, then you will also get exactly this exception. Perhaps this is happening in Jetty. To exclude the one and other, try to remove the <load-on-startup> entry so that it will be loaded only on first concrete HTTP request, far after the TLD is been processed. In any way, explicitly registering the listener in web.xml should indeed solve it.

Further, since JSF 2.x, in addition to the TLD file, the listener is also supposed to be automatically registered by a ServletContainerInitializer implementation in the JAR file in order to workaround a Glassfish 3 bug. In Mojarra 2.x this is the com.sun.faces.config.FacesInitializer class which has the following lines starting at line 131:

// The following line is temporary until we can solve an ordering
// issue in V3.  Right now the JSP container looks for a mapping
// of the FacesServlet in the web.xml.  If it's not present, then
// it assumes that the application isn't a faces application.  In this
// case the JSP container will not register the ConfigureListener
// definition from our TLD nor will it parse cause or JSP TLDs to
// be parsed.
servletContext.addListener(com.sun.faces.config.ConfigureListener.class);

This works in Servlet 3.0 containers only, such as Tomcat 7, Glassfish 3, Jetty 8 (supposedly!), etc. You seem to be using Jetty 8.0 which should thus comply Servlet 3.0, but your web.xml is declared conform Servlet 2.5, so the container will run in Servlet 2.5 fallback modus. Changing your web.xml to conform Servlet 3.0 should trigger this initializer.

One more resolve: I got this error after I created java files on the fly with CXF from wsdl.

JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, serviceName);

CXF puts its own ClassLoader (instance of URLClassLoader) to the Thread's classloader. It works the normal way, until user's thread gets into JSF's FactoryFinder, which is cached by the ClassLoader as the key. Because the ClassLoader changed, it creates a new FactoryManager, which cannot be initialized, because the implementation instance lists are removed when the original FactoryManager initiated. Because of it, the Implementation classes are not found, hence the IllegalStateException is thrown.

Solution: backup the original ClassLoader before CXF's createClient, save the URLClassLoader in a variable and put back the original ClassLoader to the Thread. When you want to access a dynamic class from CXF, search it through the URLClassLoader you put in a variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!