使用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“即可。