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

本文介绍了如何在SpringBoot项目中集成CXF以调用Web服务,包括添加必要的依赖和创建CXF工具类。同时,针对运行时出现的'Unable to create schema compiler'错误,提供了指定JRE启动并复制必要库文件的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. springboot集成cxf

		#只使用第一个应该可以,具体没测试
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
			<version>3.4.3</version>
		</dependency>
		
	
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>3.4.3</version>
		</dependency>

		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http</artifactId>
			<version>3.4.3</version>
		</dependency>

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 {
	
	/**
     * 
     * @param url webservice接口地址
     * @param operation 方法名
     * @param parameters 参数
     * @return 接口返回值
     */
    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和lib\ext文件内(网上有人说只复制到lib包下即可,实测不行)
在这里插入图片描述
在这里插入图片描述

指定jre启动jar包

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值