在java6中使用XFire时提示错误Could not initialize Service

来源:互联网 发布:汉以强亡 知乎 编辑:程序博客网 时间:2024/06/08 07:42

转自:http://blog.csdn.net/tongsh6/article/details/52077710

在一个采用了XFire作为WebService框架Web项目中,添加由JDK1.6 wsimport命令生成的一个WebService客户端调用,在客户端调用时出现了如下问题

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. log4j:WARN No appenders could be found for logger (org.codehaus.xfire.jaxws.Provider).  
  2. log4j:WARN Please initialize the log4j system properly.  
  3. Exception in thread "main" java.lang.IllegalStateException: Could not initialize Service.  
  4.     at org.codehaus.xfire.jaxws.ServiceDelegate.<init>(ServiceDelegate.java:77)  
  5.     at org.codehaus.xfire.jaxws.Provider.createServiceDelegate(Provider.java:32)  
  6.     at javax.xml.ws.Service.<init>(Service.java:56)  
  7.     at com.xxx.xxx..XXXService.<init>(XXXService.java:48)  
  8.     at com.xxx.xxx..main(Test.java:8)  
  9. Caused by: java.lang.NoSuchMethodException: com.xxx.xxx.getPortClassMap()  
  10.     at java.lang.Class.getMethod(Class.java:1607)  
  11.     at org.codehaus.xfire.jaxws.ServiceDelegate.<init>(ServiceDelegate.java:60)  
  12.     ... 4 more  

根据错误信息来看,是由于getPortClassMap()方法未找到,导致Could not initialize Service;但是我的客户端是用jdk自带的wsimport生成的,为什么在方法执行过程中会调用XFire相关的代码呢?

再仔细看错误提示,javax.xml.ws.Service.<init>(Service.Java:56),原来是这里出了问题,

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. protected Service(java.net.URL wsdlDocumentLocation, QName serviceName) {  
  2.     delegate = Provider.provider().createServiceDelegate(wsdlDocumentLocation,  
  3.             serviceName,  
  4.             this.getClass());  
  5. }  

在这个地方调用Provider的方法,而Provider在jdk6中是一个抽象类,jdk6有该类的子类com.sun.xml.internal.ws.spi.ProviderImpl,
XFire也有一个该类的子类org.codehaus.xfire.jaxws.Provider,并且在xfire-all-1.2.6.jar包中/META-INF/services/javax.xml.ws.spi.Provider的文件里,

指定了由org.codehaus.xfire.jaxws.Provider去执行。

那么现在该问题解决方式就是把javax.xml.ws.spi.Provider文件中的

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. org.codehaus.xfire.jaxws.Provider  
改为
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. com.sun.xml.internal.ws.spi.ProviderImpl  

就可以了。

这样java6的wsimport生成的客户端就不会再条用XFire相关的代码了。


本文章只记录了该问题的现象和解决方法。


0 0
原创粉丝点击