首页 > 代码库 > webservice_cxf的配置

webservice_cxf的配置

先定义一个接口

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();
    }
}

 

webservice_cxf的配置