栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot集成cxf调用webservice踩坑Unable to create schema compiler

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot集成cxf调用webservice踩坑Unable to create schema compiler

1. springboot集成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
		
2. 创建cxf工具类
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包目录中。

复制jdk下lib中tools.jar到jre的lib和libext文件内(网上有人说只复制到lib包下即可,实测不行)

指定jre启动jar包

start jre1.8.0/bin/java -jar -Dspring.config.location=application.yml -Dfile.encoding=utf-8 xxx.jar

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/332877.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号