Axis2在Web項目中整合Spring

來源:互聯網
上載者:User

Axis2在Web項目中整合Spring

一、說明:

上一篇說了Axis2與Web項目的整合過程,如果說在Web項目中使用了Spring架構,那麼又改如何進行Axis2相關的配置操作呢?

二、Axis2 與 Spring 整合

① 建立項目 AxisSpringDemo,並在其中加入 Axis2 與 Spring 相關的 jar 包

Spring所需 Jar :

 

aopalliance-1.0.jaraspectjrt.jaraspectjweaver.jarspring-aop-3.2.1.RELEASE.jarspring-beans-3.2.1.RELEASE.jarspring-context-3.2.1.RELEASE.jarspring-core-3.2.1.RELEASE.jarspring-expression-3.2.1.RELEASE.jarspring-tx-3.2.1.RELEASE.jarspring-web-3.2.1.RELEASE.jar
Axis2 所需 Jar :

 

 

activation-1.1.jaraxiom-api-1.2.15.jaraxiom-impl-1.2.15.jaraxis2-adb-1.6.4.jaraxis2-jaxws-1.6.4.jaraxis2-kernel-1.6.4.jaraxis2-spring-1.6.4.jaraxis2-transport-http-1.6.4.jaraxis2-transport-local-1.6.4.jaraxis2-xmlbeans-1.6.4.jarcommons-fileupload-1.3.1.jarcommons-httpclient-3.1.jarcommons-io-2.1.jarcommons-logging-1.1.1.jargeronimo-stax-api_1.0_spec-1.0.1.jarhttpcore-4.0.jarjsr311-api-1.1.1.jarmail-1.4.jarneethi-3.0.2.jarwoden-api-1.0M9.jarwsdl4j-1.6.2.jarxml-resolver-1.2.jarXmlSchema-1.4.7.jar

 

② 在工程中的 web.xml 檔案中加入 Spring 、 Axis2支援配置:

 

        contextConfigLocation    classpath:applicationContext.xml        org.springframework.web.context.ContextLoaderListener                 AxisServlet        org.apache.axis2.transport.http.AxisServlet        1            AxisServlet        /services/*  

 

③ 同上篇講的整合 web項目一致 ,將conf 、axis2-web 、modules檔案夾移動到 AxisSpringDemo工程的 下各個對應的位置。

④ 在src下建立包 com.elgin.spring.webservice ,並建立提供WebService服務的類 SpringWebServiceDemo ,代碼如下:

 

package com.elgin.spring.webservice;import java.util.Random;import org.springframework.stereotype.Component;@Component("springWebService")public class SpringWebServiceDemo {    public String springHello(){return "hello spring-axis2"; }public int getAge(){return new Random().nextInt(80);}public void update(){System.out.println("update something..");}}

 

⑤ 在類路徑下建立 Spring設定檔 :applicationContxt.xml 設定檔

 

 
⑥ 配置 Axis2的WebService服務:

 

同上一篇所說:在 AxisWebDemo 工程的 WEB-INF 下建立如下階層目錄 : services/springServices/META-INF/services.xml

services.xml配置內容:

 

             Web Service               springWebService      org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier                                                              
三、測試總結:

 

經過上述的步驟,配置結束,將項目裝載的 Tomcat ,啟動 ,訪問:http://localhost:8080/AxisSpringDemo/services/listServices 出現如下介面:

通過上面的測試可以發現:

加入Spring之後,除了spring的引入以及配置,唯一不同的地方就是 services.xml 的配置發生了變化.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.