« Canging from @Manage... | Main | JSF 2.0 - Action... »

JSF 2.0 - could not find Factory...

Today I notice that when I deploy my JSF 2 webapp on GlassFish 3.1, i have this error :

java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory


To avoid this error message it you should add the listener "com.sun.faces.config.ConfigureListener" into the web.xml.
But you will still see the error message again if your FacesServlet has the load-on-startup option "1".
This option will avoid that the ConfigureListern is loaded before the FacesServlet starts.

So use the following setup for your web.xml file (3.0):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
....
<!-- ============== 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>
....
<!-- Facelets -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
......

>

It is important to set the load-on-startup setting to 0
See also further Information here.