spring整合cxf架構,springcxf架構

來源:互聯網
上載者:User

spring整合cxf架構,springcxf架構

CXF是webService的架構,能夠和spring無縫整合

##服務端編寫

1.建立動態web項目

2.匯入cxf和spring相關jar包(CXF核心包:cxf-2.4.2.jar)

3.在web.xml中配置CXF架構的核心Servlet

 1 <servlet> 2       <servlet-name>cxf</servlet-name> 3       <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 4       <init-param> 5           <param-name>config-location</param-name> 6           <param-value>classpath:applicationContext.xml</param-value> 7       </init-param> 8   </servlet> 9   <servlet-mapping>10       <servlet-name>cxf</servlet-name>11       <url-pattern>/webservice/*</url-pattern>12   </servlet-mapping>

4.提供spring架構的設定檔applicationContext.xml

  applicationContext.xml的約束:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"xmlns:soap="http://cxf.apache.org/bindings/soap"xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://cxf.apache.org/bindings/soap                     http://cxf.apache.org/schemas/configuration/soap.xsd                    http://cxf.apache.org/jaxws                     http://cxf.apache.org/schemas/jaxws.xsd">

5.開發一個服務類

  注:服務類必須加註解  @WebService

6.在spring中設定檔中註冊服務

<jaxws:endpoint id="" address="/hello" implementor=""></jaxws:endpoint><!-- id為服務的id,任意填寫 address 為訪問地址  implementor為服務類的全類名-->

啟動web工程,瀏覽器訪問

 

###用戶端

    (用wsdl2java命令產生本地代碼調用)

1,在wsdl2java.bat命令所在的檔案夾下開啟命令視窗,輸入:wsdl2java -d . 路徑

(路徑為service發布後頁面的wsdl的全路徑,service訪問的路徑名加?wsdl),斷行符號後會在當前檔案夾下組建檔案夾

2.把檔案夾複製到項目中

    (用spring檔案註冊代理對象調用)

1.建立項目,可以不是web項目,匯入jar包

2.將產生的介面複製到項目中,

3.建立applicationContext.xml檔案中配置代理對象

<jaxws:client id="" address = "" serviceClass =""></jaxws:client><!-- id值隨意, adress的值為wsdl的路徑值,當不在本機是,須要修改ip serviceClass為介面的全路徑-->

4.編寫實作類別(如下為例子)

public static void main(String[] args) {        //建立工廠對象        ClassPathXmlApplicationContext cts = new ClassPathXmlApplicationContext("applicationContext.xml");        Fun1 proxy = (Fun1) cts.getBean("myclient");        String string = proxy.sayHello("呵呵", 12);        System.out.println(string);    }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.