Posts Tagged ‘embedded tomcat’

Eureka moment – “could not find Factory: javax.faces.context.FacesContextFactory” and embedded tomcat and grails

August 23, 2013 Leave a comment

Whoa – major breakthrough

I have been to build a grails project and get it to use JSF and have kept running into problems like this when building grails plugin projects and trying to publish to the embedded tomcat – which I have tried and failed for about a year to get to the bottom of without success

INFO: Initializing Spring root WebApplicationContext
Aug 23, 2013 11:53:20 AM javax.faces.FactoryFinder$FactoryManager copyInjectionProviderFromFacesContext
SEVERE: Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
Aug 23, 2013 11:53:20 AM javax.faces.FactoryFinder$FactoryManager getFactory
SEVERE: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory. Attempting to find backup.
Aug 23, 2013 11:53:20 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(
at javax.faces.FactoryFinder.getFactory(
at javax.faces.webapp.FacesServlet.init(
at org.apache.catalina.core.StandardWrapper.initServlet(
at org.apache.catalina.core.StandardWrapper.loadServlet(

Then I was having the problem again this morning – must fourth attempt at getting past this little hurdle when I ran into the following item hidden away beneath google

about half way down there is a tiny comment about programmatically adding ctx.addListener(com.sun.faces.config.ConfigureListener.class); and the fact that the web.xml cant be found.

what it suggests you do is to add the following ctx.addContextInitParameter(“com.sun.faces.forceLoadConfiguration”, “true”);

so I tried the equivalent of this for the embedded comcat example in my plugin by adding this context param to the generated web.xml in the doWithXML closure in the plugin file

    def doWithWebDescriptor = { xml ->
        // TODO Implement additions to web.xml (optional), this event occurs before
		def contextParams = xml.'context-param'[0]
		contextParams + {
			'context-param' {
				'param-name' ('javax.faces.DEFAULT_SUFFIX')
				'param-value' ('.xhtml')
			'context-param' {
				'param-name' ('javax.faces.PROJECT_STAGE')
				'param-value' ('Development')
			'context-param' {
				'param-name' ('javax.faces.STATE_SAVING_METHOD')
				'param-value' ('client')
			'context-param' {
				'param-name' ('javax.faces.FACELETS_REFRESH_PERIOD')
				'param-value' ('1')

			'context-param' {
				'param-name' ('com.sun.faces.injectionProvider')
				//'param-value' ('com.sun.faces.vendor.WebContainerInjectionProvider')
				'param-value' ('com.softwood.SpringInjectionProvider')

			//use this for embedded tomcat when web.xml is defined programatically and its not in the project directly
			'context-param' {
				'param-name' ('com.sun.faces.forceLoadConfiguration')
				'param-value' ('true')

now when you run it the plugin starts and correctly loads the faces config context and your app works ! Holly cow batman

think i’m going to log this as a bug under the grails jira and see if someone cleverer than me can figure out the why’s – but heigh that now works in embedded tomcat – hoorah

%d bloggers like this: