Axis2在Web项目中整合Spring
一、说明:
上一篇说了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的更多相关文章
- spring web项目中整合netty, akka
spring web项目中整合netty, akka 本身的web项目仍然使用tomcat/jetty8080端口, 在org.springframework.beans.factory.Initia ...
- 06_在web项目中集成Spring
在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...
- web项目中 集合Spring&使用junit4测试Spring
web项目中 集合Spring 问题: 如果将 ApplicationContext applicationContext = new ClassPathXmlApplicationContext(& ...
- 如何在web项目中配置Spring的Ioc容器
在web项目中配置Spring的Ioc容器其实就是创建web应用的上下文(WebApplicationContext) 自定义要使用的IoC容器而不使用默认的XmlApplicationContext ...
- web项目中获取spring的bean对象
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架,如何在程序中不通过注解的形式(@Resource.@Autowired)获取Spring配置的bean呢? Bean工厂(c ...
- 如何在Web项目中配置Spring MVC
要使用Spring MVC需要在Web项目配置文件中web.xml中配置Spring MVC的前端控制器DispatchServlet <servlet> <servlet-name ...
- 在普通WEB项目中使用Spring
Spring是一个对象容器,帮助我们管理项目中的对象,那么在web项目中哪些对象应该交给Spring管理呢? 项目中涉及的对象 我们回顾一下WEB项目中涉及的对象 Servlet Request ...
- java web项目中引入spring
自己动手实践了一次,发生中间出了一下问题,现整理出来,供参考. Step1: 新建一个java web项目 Step2:下载spring的jar包http://repo.spring.io/libs- ...
- web项目中加入struts2、spring的支持,并整合两者
Web项目中加入struts2 的支持 在lib下加入strut2的jar包 2. 在web.xml中添加配置 <filter> <filter-name>struts2< ...
随机推荐
- java.io.EOFException java.io.ObjectInputStream$PeekInputStream.readFully 错误
Tomcat 启动时 java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully 错误 这 个错误 碰到好几 ...
- laravel中的$request对象构造及请求生命周期
laravel应用程序中index.php是所有请求的入口.当用户提交一个form或者访问一个网页时,首先由kernel捕捉到该session PHP运行环境下的用户数据, 生成一个request对象 ...
- PHP后台执行
php中实现后台执行的方法: ignore_user_abort(true); // 后台运行set_time_limit(0); // 取消脚本运行时间的超时上限后台运行的后面还要,set_time ...
- java基础:数据类型
一:基本数据类型 (1):整数类型 byte,short,int,long (2):浮点类型 float , double (3):布尔类型 boolean 注意: long 类型的变量后面要 ...
- I.MX6 Linux mipi配置数据合成
/*************************************************************************** * I.MX6 Linux mipi配置数据合 ...
- REDHAT YUM使用网易源
刚装好了 RedHat 6 系统,但是使用 yum 的时候总是提示 nothing to do,并且什么都做不了.后来经过一番搜索才知道,红帽的 yum 在线更新是收费的,而且必须注册系统之后才能使用 ...
- jboss集成eclipse
eclipse Kepler + Jboss7.1 参考引用文档: http://www.tekdigest.com/how-to-install-jboss-tools-in-eclipse.htm ...
- Linux下ps命令
简述 Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,动态的显示进程信息 ...
- Android 开源项目DiskLruCache 详解
有兴趣的同学可以读完这篇文章以后 可以看看这个硬盘缓存和volley 或者是其他 图片缓存框架中使用的硬盘缓存有什么异同点. 讲道理的话,其实硬盘缓存这个模块并不难写,难就难在 你要考虑到百分之0.1 ...
- js仿手机端九宫格登录功能
js仿手机端九宫格登录功能 最近闲来无事把以前无聊时开发的小东西拿出来和大家分享下,写的不好的请指出,我会及时修改.谢谢. 功能及方法逻辑都注释在代码中.所以麻烦大家直接看代码. 效果如下: 话不多说 ...