先定义一个接口
import javax.jws.WebService; @WebService public interface HelloWorld { public void sayhi(); }
实现它
import javax.jws.WebService; @WebService(endpointInterface="webservice_cxf.HelloWorld",serviceName="HelloWorld") public class HelloWorldImpl implements HelloWorld{ public void sayhi() { System.out.println("hello world"); } }
发布它
import javax.xml.ws.Endpoint;
public class Public {
public static void main(String[] args) {
System.out.println("web service start");
HelloWorld implementor = new HelloWorldImpl();
String address = "http://localhost:8080/helloWorld";
Endpoint.publish(address, implementor);
System.out.println("+++web service started");
}
}
测试它
public class Client { public static void main(String[] args) { JaxWsProxyFactoryBean jwpfb = new JaxWsProxyFactoryBean(); jwpfb.setServiceClass(HelloWorld.class); jwpfb.setAddress("http://localhost:8080/helloWorld"); HelloWorld hw = (HelloWorld) jwpfb.create(); hw.sayhi(); } }
原文:http://www.cnblogs.com/flovatoblog/p/6071044.html