cxf+spring發布webservice服務(客戶端)

ymc4 9年前發布 | 54K 次閱讀 Apache CXF WEB服務/RPC/SOA WebService

首先創建接口,與服務器一樣的接口

@WebService
public interface HelloWorld {

    public String sayHello(String name);

}

再在classpath下新建beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://cxf.apache.org/jaxws
                        http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:client 
        id="cxfClient"
        address="http://localhost:8080/cxf-Spring-server/Hello"
        serviceClass="com.spg.cxfSpring.dao.HelloWorld" />

</beans>

最后在編寫客戶端代碼,調用服務器端的接口

public class Client {

    public static void main(String[] args) {

        BeanFactory factory = new ClassPathXmlApplicationContext("beans.xml");
        HelloWorld hello = (HelloWorld) factory.getBean("cxfClient");
        System.out.println(hello.sayHello("spg"));

    }

}

運行結果,得到服務器端的返回數據。


 本文由用戶 ymc4 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!