1. 下载cxf包,下载地址为:http://archive.apache.org/dist/cxf/2.3.3/apache-cxf-2.3.3.zip
2. 将下载的包解压,将lib下的所有jar包添加到自己的工程目录中。如果添加最少的jar ,那可以谷歌一下。
3. 编写一个HelloWorldService接口(在接口处打上@WebService注解标志,形参一定得打上注解标志,不然在url访问时就不能直接传参了):
package org.server;
import javax.jws.WebService;
@WebService
public interface IHelloWorldService {
public String sayHello(@WebParam(name = "name") String name);
}
4.编写HelloWorldService的实现:
package org.server;
public class HelloWorldService implements IHelloWorldService{
public String sayHello(@WebParam(name = "name") String name) {
return name + " say: Hello World ";
}
}
5.发布上面的这个webservice简单服务
package org.deploy;
import javax.xml.ws.Endpoint;
import org.server.HelloWorldService;
import org.server.IHelloWorldService;
public class DeployHelloWorldService {
public static void deployService() throws InterruptedException {
System.out.println("Server start ……");
IHelloWorldService service = new HelloWorldService();
String address = "http://localhost:8090/helloWorld";
Endpoint.publish(address, service);
}
public static void main(String[] args) throws InterruptedException{
deployService();
}
6.一个简单的webService就做好了,不需要放在tomcat中就可以访问,因为cxf内置了jetty微型容器。在ie中输入 http://localhost:8090/helloWorld?wsdl就可以访问这个服务了。如果想传入参数测试一下就用下面这个: http://localhost:8090/helloWorld/sayHello?name=8888