这是本人在使用cxf开发Web Service遇到的问题,创建例子的项目步骤请参照:http://cxf.apache.org/docs/writing-a-service-with-spring.html 。下面本人创建例子过程当中遇到的问题,以及如何解决的,希望这样对读者有所帮助。
问题清单1
异常:FileNotFoundException 不能找到META-INF/cxf/cxf.xml。因为此文件放置在cxf-rt-core-xxxx.jar包中,所以请你确保class路径下有jar包。本人是使用Maven来构建项目的,所以在添加依赖时,需要添加如下依赖
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.3.4</version>
</dependency>
CXF其他模块的依赖,请参照http://cxf.apache.org/docs/using-cxf-with-maven.html 。
问题清单2
org.apache.cxf.BusException : No binding factory for namespace http://schemas.xmlsoap.org/wsdl/soap/ registered。在apache cxf教程中,cxf-servlet.xml文件中有如下的配置:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
解决的办法就是还需要增加一项:
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
问题清单3
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.出错原因:
private static final QName SERVICE_NAME = new QName(
"http://server.hw.demo/", "HelloWorld" );
private static final QName PORT_NAME = new QName("http://server.hw.demo/" ,
"HelloWorldPort");
中的URL不与真实包路径成相反。解决方法将http://server.hw.demo/。 改成与真实包路径完全相反。我的包路径为com.paleolake.system.webservice.cxf.jaxws,所以,我需要修改为
http://jaxws.cxf.webservice.system.paleolake.com/