首先还是下包 目前最新的CXF的下载地址http://cxf.apache.org/download.html,解压apache-cxf-3.0.2.zip
取该目录下的lib中的所有jar包放入项目中即可,samples目录下游很多实例可以用在参考
列举一个HellWorld
1.建立服务节点接口
package com.cxf.helloworld;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* 首先服务点接口
*/
@WebService
public interface HelloWorld {
String sayHi(@WebParam(name="text")String text);
}
2.编写服务实现
package com.cxf.helloworld;
import javax.jws.WebService;
/**
* 编写服务实现
*/
@WebService(endpointInterface="com.cxf.helloworld.HelloWorld",serviceName="helloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello"+text;
}
}
3.编写 WebServiceApp类来暴露 web服务
package com.cxf.helloworld;
import javax.xml.ws.Endpoint;
public class WebServiceApp {
/**
* 编写 WebServiceApp类来暴露 web服务
*/
public static void main(String[] args) {
System.out.println("Starting Server");
HelloWorldImpl implementor = new HelloWorldImpl();
//http://localhost:9000/HelloWorld?wsdl
String address = "http://localhost:9000/HelloWorld";
Endpoint.publish(address, implementor);
System.out.println("Started Server");
}
}
运行WebServiceApp 打印 Started Server说明webService服务已经启动 访问 http://localhost:9000/HelloWorld?wsdl
看是否生成了我们所需要的wsdl文件