#只使用第一个应该可以,具体没测试2. 创建cxf工具类org.apache.cxf cxf-spring-boot-starter-jaxws 3.4.3 org.apache.cxf cxf-rt-frontend-jaxws 3.4.3 org.apache.cxf cxf-rt-transports-http 3.4.3
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.springframework.stereotype.Service;
import javax.xml.namespace.QName;
@Service
public class CXFUtils {
public static Object[] invokeRemoteMethod(String url, String operation, Object[] parameters) {
Object[] res = null;
try {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
if (!url.endsWith("wsdl")) {
url += "?wsdl";
}
org.apache.cxf.endpoint.Client client = dcf.createClient(url);
//处理webService接口和实现类namespace不同的情况,CXF动态客户端在处理此问题时,会报No operation was found with the name的异常
Endpoint endpoint = client.getEndpoint();
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), operation);
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
if (operation.equals(operationInfo.getName().getLocalPart())) {
opName = operationInfo.getName();
break;
}
}
}
res = client.invoke(opName, parameters);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
}
3. 踩坑记录
解决办法:1、 idea编辑器中测试正常,jar包运行时调用webservice提示 Unable to create schema compiler
指定jre启动,为避免引起其他项目出错,复制jdk目录下jre包到jar包目录中。
指定jre启动jar包复制jdk下lib中tools.jar到jre的lib和libext文件内(网上有人说只复制到lib包下即可,实测不行)
start jre1.8.0/bin/java -jar -Dspring.config.location=application.yml -Dfile.encoding=utf-8 xxx.jar



