cxf spring

使用cxf时,遇到几个问题,记录一下:

问题1:配置文件有两种方式可以配置:

第一种:使用jaxws:endpoint

<jaxws:endpoint id="test" implementor="#testImpl" address="/test" />
第二种:使用jaxws:server

<jaxws:server id="test" serverClass="com.Test" address="/test">
    <jaxws:serviceBean>
        <ref bean="testImpl" />
    </jaxws:serviceBean>
</jaxws:server>

问题2:客户端调用有两种方式

第一种:需要复制服务端的接口类到客户端,或者使用wsdl2java工具也可以(未测试)

<span style="white-space:pre">	</span>public static void main(String[] args) {
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(TestCxf.class);
		factory.setAddress("http://localhost:8080/cxfwebservice/test?wsdl");
		TestCxf s = (TestCxf)factory.create();
		System.out.println("第一种方法测试==="+s.tttt());
		System.exit(0);
	}
第二种:不需要复制
<span style="white-space:pre">		</span>JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 
		String url = "http://localhost:8080/cxfwebservice/test?wsdl"; //wsdl地址
		String method = "tttt";
		Client client = dcf.createClient(url);
		Object[] res = null;
		try{
			res = client.invoke(method);
		}catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("第二种方法测试=="+res.length);
		System.exit(0)

第三个问题:调用上面第二种方式 的时候,可能会报错“com.sun.tools.internal.xjc.api.XJC”等报错信息,加载jdk/lib下的tools.jar包即可


第四个问题:调用第二种方式之后再次调用第一种方式,也可能给会报错“

the namespace on the "definitions" element, is not atorChain doIntercept Interce

以及”the namespace on the "definitions" element, is not a valid SOAP version“等报错信息
按照以上链接的解决办法,去掉第一种方式地址中的”?wsdl“即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值