Axis: rt.jar和jaxrpc中javax.xml.namespace.QName冲突问题分析

来源:互联网 发布:知金教育官网 编辑:程序博客网 时间:2024/06/05 01:15

Axis: rt.jar和jaxrpc中javax.xml.namespace.QName冲突问题分析

=================================================

       在项目中,已经加入了axis依赖包,原有的功能调用了axis开发web services,其中需要用到axis的依赖jar包jaxrpc.jar。另一个同事,在该项目中添加新的功能,用CXF调用实现调用web service接口。

Apache CXF调用接口的关键代码如下:

在下面这个方法中用到的QName要调用的是rt.jar中javax.xml.namespace.QName。

public class Invoice {   private static final QName SERVICE_NAME =  new QName("ld:Logical/IpsInvFunctions_ws", "IpsInvFunctionsSoapService");     URL wsdlURL = null;   public void getInvoice(String code)throws Exception{   wsdlURL = new URL("http://172.25.11.243:7001/project/invoice.ws?wsdl");   IpsInvFunctionsSoapService ss = new IpsInvFunctionsSoapService(wsdlURL, SERVICE_NAME);   IpsInvFunctionsPT port = ss.getIpsInvFunctionsSoapPort();    GetInvoice element = new GetInvoice();   element.setVInvoice(code);   GetInvoiceResponse resp = port.getInvoice(element);   byte[] blobData = resp.getIPSINVOICEFILE().getINVOICEFILE();   }   }


此时,项目的weblogic.xml配置文件中配置了先加载项目用的jar:

<?xml version="1.0" encoding="UTF-8"?><wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.2/weblogic-web-app.xsd"><wls:weblogic-version>10.3.5</wls:weblogic-version><wls:context-root>3BizOnlinev3N</wls:context-root><wls:charset-params><wls:input-charset><wls:resource-path>/*</wls:resource-path><wls:java-charset-name>UTF-8</wls:java-charset-name></wls:input-charset></wls:charset-params><wls:jsp-descriptor><wls:keepgenerated>true</wls:keepgenerated><wls:precompile>false</wls:precompile></wls:jsp-descriptor><span style="color:#cc0000;"><wls:container-descriptor><wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes></wls:container-descriptor></span></wls:weblogic-web-app>


所以,按照类库加载的顺序,先加载项目中依赖的jar,再加载jre/lib/rt.jar;在加载完jaxrpc.jar后,内存中已有一个javax.xml.namespace.QName类,再load rt.jar的时候,不会再载入rt.jar中javax.xml.namespace.QName类,所以在使用CXF调用web services时,就会报类冲突的错误:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.ws.Service.<init>(Ljava/net/URL;Ljavax/xml/namespace/QName;)V" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the current class, com/hthk/webservice/ips/IpsInvFunctionsSoapService, and the class loader (instance of <bootloader>) for resolved class, javax/xml/ws/Service, have different Class objects for the type javax/xml/namespace/QName used in the signatureat com.hthk.webservice.ips.IpsInvFunctionsSoapService.<init>(IpsInvFunctionsSoapService.java:46)at com.hthk.action.IpsInvoiceFileAction.queryBill(IpsInvoiceFileAction.java:76)... 103 more

        按照项目的实际请求,解决的办法的办法只能把CXF调用Web services的方式改成用axis。

        用axis生成stub类的步骤:

        (1)加入axis的依赖包;

                  

                  axis.jar                  commons-discovery-0.2.jar                  commons-logging.jar                  jaxrpc.jar                  saaj.jar                  wsdl4j.jar

          (2)通过浏览器下载wsdl文件,并将文件复制到项目src目录下

          (3)选中wsdl文件右键->Web Services->Generate Client ,然后选择Web Servic客户端代码的生成路径,选择完成后点击“完成”:

          (4)直接使用*Proxy类即可。

                    可以参考:http://blog.csdn.net/a19881029/article/details/24641551

                    


0 0