一、说明:

上一篇说了Axis2与Web项目的整合(详情 :Axis2与Web项目整合)过程,如果说在Web项目中使用了Spring框架,那么又改如何进行Axis2相关的配置操作呢?

二、Axis2 与 Spring 整合

①   新建项目 AxisSpringDemo,并在其中加入 Axis2 与 Spring 相关的 jar 包

Spring所需 Jar :

aopalliance-1.0.jar
aspectjrt.jar
aspectjweaver.jar
spring-aop-3.2.1.RELEASE.jar
spring-beans-3.2.1.RELEASE.jar
spring-context-3.2.1.RELEASE.jar
spring-core-3.2.1.RELEASE.jar
spring-expression-3.2.1.RELEASE.jar
spring-tx-3.2.1.RELEASE.jar
spring-web-3.2.1.RELEASE.jar

Axis2 所需 Jar :

activation-1.1.jar
axiom-api-1.2.15.jar
axiom-impl-1.2.15.jar
axis2-adb-1.6.4.jar
axis2-jaxws-1.6.4.jar
axis2-kernel-1.6.4.jar
axis2-spring-1.6.4.jar
axis2-transport-http-1.6.4.jar
axis2-transport-local-1.6.4.jar
axis2-xmlbeans-1.6.4.jar
commons-fileupload-1.3.1.jar
commons-httpclient-3.1.jar
commons-io-2.1.jar
commons-logging-1.1.1.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
httpcore-4.0.jar
jsr311-api-1.1.1.jar
mail-1.4.jar
neethi-3.0.2.jar
woden-api-1.0M9.jar
wsdl4j-1.6.2.jar
xml-resolver-1.2.jar
XmlSchema-1.4.7.jar

②  在工程中的 web.xml 文件中加入 Spring 、 Axis2支持配置:

 <!-- 加入Spring支持 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--加入Axis2支持 -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

③  同上篇讲的整合 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 配置文件

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 配置spring注解扫描的包 -->
<context:component-scan base-package="com.elgin"></context:component-scan> </beans>

⑥  配置 Axis2的WebService服务:

同上一篇所说:在 AxisWebDemo 工程的 WEB-INF 下新建如下层次结构目录 : services/springServices/META-INF/services.xml

services.xml配置内容:

<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
<service name="springService">
<description>Web Service</description>
<!--
作用类似于普通配置中的 ServiceClass ,都是用来创建服务类对象,
只不过普通配置使用反射来创建
加入Spring之后,对象的创建交给了Spring的IOC容器
-->
<parameter name="SpringBeanName">springWebService</parameter>
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<!--
在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。
例如,getAge方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,
而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。
-->
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
</serviceGroup>

三、测试总结:

经过上述的步骤,配置结束,将项目装载的 Tomcat ,启动 ,访问:http://localhost:8080/AxisSpringDemo/services/listServices 出现如下界面:

通过上面的测试可以发现:

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

Axis2在Web项目中整合Spring的更多相关文章

  1. spring web项目中整合netty, akka

    spring web项目中整合netty, akka 本身的web项目仍然使用tomcat/jetty8080端口, 在org.springframework.beans.factory.Initia ...

  2. 06_在web项目中集成Spring

    在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...

  3. web项目中 集合Spring&使用junit4测试Spring

    web项目中 集合Spring 问题: 如果将 ApplicationContext applicationContext = new ClassPathXmlApplicationContext(& ...

  4. 如何在web项目中配置Spring的Ioc容器

    在web项目中配置Spring的Ioc容器其实就是创建web应用的上下文(WebApplicationContext) 自定义要使用的IoC容器而不使用默认的XmlApplicationContext ...

  5. web项目中获取spring的bean对象

    Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架,如何在程序中不通过注解的形式(@Resource.@Autowired)获取Spring配置的bean呢? Bean工厂(c ...

  6. 如何在Web项目中配置Spring MVC

    要使用Spring MVC需要在Web项目配置文件中web.xml中配置Spring MVC的前端控制器DispatchServlet <servlet> <servlet-name ...

  7. 在普通WEB项目中使用Spring

    Spring是一个对象容器,帮助我们管理项目中的对象,那么在web项目中哪些对象应该交给Spring管理呢? 项目中涉及的对象 ​ 我们回顾一下WEB项目中涉及的对象 Servlet Request ...

  8. java web项目中引入spring

    自己动手实践了一次,发生中间出了一下问题,现整理出来,供参考. Step1: 新建一个java web项目 Step2:下载spring的jar包http://repo.spring.io/libs- ...

  9. web项目中加入struts2、spring的支持,并整合两者

    Web项目中加入struts2 的支持 在lib下加入strut2的jar包 2. 在web.xml中添加配置 <filter> <filter-name>struts2< ...

随机推荐

  1. c#获取机器唯一识别码

    前言 在客户端认证的过程中,我们总要获取客户机的唯一识别信息,曾经以为MAC地址是不会变的,但是现在各种改,特别是使用无线上网卡,MAC地址插一次变一次,所以这样使用MAC就没有什么意义了,怎么办,又 ...

  2. class JOIN

    class JOIN :public Sql_alloc { JOIN(const JOIN &rhs); /**< not implemented */ JOIN& opera ...

  3. Qt之QTableView显示富文本

    简述 对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的d ...

  4. HDU 1158 Employment Planning

    又一次看题解. 万事开头难,我想DP也是这样的. 呵呵,不过还是有进步的. 比如说我一开始也是打算用dp[i][j]表示第i个月份雇j个员工的最低花费,不过后面的思路就完全错了.. 不过这里还有个问题 ...

  5. [转] Qt 多线程学习

    Qt 多线程学习 转自:http://www.cnblogs.com/IT-BOY/p/3544220.html 最近的项目上用到了关于多线程的知识,自己也比较感兴趣,所以就拿了那本<C++ G ...

  6. mongodb数据备份与还原

    1)简单数据的导出与导入导出:./mongoexport -d test -c users -o /tmp/users.out 导入:./mongoimport -d test -c users /t ...

  7. HDU 5384 Danganronpa (Trie树)

    题意:给出两个集合S和T,集合中每个元素是个字符串,而T集合中任一元素都是个子弹,可以打S中的任一怪物,如果子弹是怪物的子串,那么才有伤害值1,若在怪物中出现多次,次数为该子弹打到该怪物的伤害值.每个 ...

  8. 解读 Windows Azure 存储服务的账单 – 带宽、事务数量,以及容量

    经常有人询问我们,如何估算 Windows Azure 存储服务的成本,以便了解如何更好地构建一个经济有效的应用程序.本文我们将从带宽.事务数量,以及容量这三种存储成本的角度探讨这一问题. 在使用 W ...

  9. Hive技术文档

    Hive是什么? Hive是蜂房的意思,为什么hadoop上的这层数据仓库叫Hive? 因为生物学上蜂房是一个结构相当精良的建筑,取名Hive足见则个数据仓库在数据存储上也是堪称精良的.Hive是Fa ...

  10. 用list<类>集合接收一个网址返回的一个类的集合的XML

    JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = Share.Helper.HttpRequest ...