rss· 投稿· 设为首页· 加入收藏· 繁體版

JSF调用CXF问题解决

在jsf 中使用cxf的动态客户端访问 webservice,报错
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ws.strikeiron.com/IPLookup2?wsdl");
报错为:

The error:
No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions! If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml. A typical config looks like this; org.apache.myfaces.webapp.StartupServletContextListener
Caused by: java.lang.IllegalStateException - No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions! If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml. A typical config looks like this; org.apache.myfaces.webapp.StartupServletContextListener
----------------------------------
产生错误的原因是 cxf在生成client时,替换了当前线程的类装载器。导致 后面 jsf 执行中,上下文信息的丢失。
解决方法是在调用cxf之前 取出 当前 线程的类装载器。 调用完毕后,再写回。
ClassLoader cl = Thread.currentThread().getContextClassLoader();

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ws.strikeiron.com/IPLookup2?wsdl");
Thread.currentThread().setContextClassLoader(cl);



顶一下
(0)
踩一下
(0)