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

后端 未结 3 1604
温柔的废话
温柔的废话 2020-11-29 04:41

I notice that when trying to setup my JSF 2 webapp running on jetty, i have this error :

java.lang.IllegalStateException: Application was not properly

3条回答
  •  天涯浪人
    2020-11-29 05:10

    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.

提交回复
热议问题