`
roc08
  • 浏览: 224255 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

cxf webservice调用有两个报错--类加载问题

阅读更多
目前系统webservice调用有两个报错
1. Can not set final com.sun.tools.internal.xjc.reader.internalizer.InternalizationLogic field com.sun.tools.internal.xjc.reader.internalizer.DOMForest.logic to org.apache.cxf.endpoint.dynamic.DynamicClientFactory
2. java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFactory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom

关于问题1
是由于cxf-api-2.7.8.jar中未导入对com.sun.tools.xjc.api的依赖导致加载的SchemaCompilerImpl 是系统tools中实现的,在后面设置值时不匹配报错.修改cxf-api-2.7.8.jar加入对com.sun.tools.xjc.api即不报错,貌似不影响正常使用,且cxf-api后续版本都没有加入此引用,故没处理.



关于问题2 是由于找不到XPathFactory的实现类,对于某些webservice可用,某些不可用是由于XPathFactory的类加载机制很特殊
(1) 在加载过程中(XPathFactoryFinder类中)首先以XPathFactory的类全名和默认的http://java.sun.com/jaxp/xpath/dom去SystemProperty中取,如果有就创建实例
(2) 没有的话就去java home中有没有jaxp.properties文件,如果有就根据这个文件去取
(3) 没有的话就去看META-INF/services是不是配置了Factory的实现类,如果有就根据这个取
(4) 没有的话就去创建默认的类实现,此类在rt.jar中。



(1) com.sun.tools.xjc.reader.internalizer. Internalizer初始化时需要
private static final XPathFactory xpf = XPathFactory.newInstance(); 这时会将默认的http://java.sun.com/jaxp/xpath/dom代入取factory,
(2) 取factory的XPathFactory的newInstance方法会使用 ClassLoader classLoader = ss.getContextClassLoader();
(3) getContextClassLoader中使用Thread.currentThread().getContextClassLoader();获取当前线程的类加载器
因为是获取的当前线程的加载器,在实际运行过程中发现有些是webAppClassLoader有些是BundleAwire形式,这些是可以加载到com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl类的。而有些情况下是BundleDelegatingClassLoader(BundleDelegatingClassLoader for [glodon.gem.extend (glodon.gem.extend)]),这时是加载不到此类的。
由于是rt.jar中的类应该委托到bootstrap加载器,故只需将其配置到org.osgi.framework.bootdelegation中即可,


最后一个问题,为啥以前好使现在不好使了,是由于以前这里配置了,后来整理时被干掉了,因此这个webservice不好使了。
  • 大小: 34 KB
  • 大小: 6.4 KB
  • 大小: 63.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics