`

web应用axis2整合spring

阅读更多
环境:axis2 1.4, spring1.2 或者 spring2.0, tomcat6.0, windows vista

由于项目需要搭建一个良好的架构,我选择了用axis2和spring整合。不过再还没有做的时候,就听同事和网上的朋友说axis2和spring整合是多么难的事,使得我有一种极度想挑战它的心理,哈,其实整合起来非常的容易,不过网上介绍axis2的不多。我是用axis2官方网站的方法做整合的。地址:http://ws.apache.org/axis2/1_4_1/spring.html
官方网站上介绍两种方式整合,一种是我们所熟悉的applicationContext.xml放在和web.xml同一级的目录下,第二种是放在aar里面。因为任务上的一些因素,我选用第一种方式,而且我也只记录第一种,第二种我没有研究,我怕说错了误人子弟,好啦,开始。

1、首先,需要axis2.war,根据它的目录结构我们修改自己的web应用。只需拷贝axis2/WEB-INF/目录下的所有文件到自己的web项目下就可以了,记得要覆盖所有(axis2-web这个文件夹是包含axis2整个的管理界面,可有可无,不过要用的话,记得它是放在和WEB-INF的同级目录下),其实我们就是有点像在整个的axis2工程上做二次开发。

2、我们像做所有其它的Web项目一样,用到spring的时候拷贝spring.jar到WEB-INF/lib目录下,然后在web.xml同级的目录下建立一个 applicationContext.xml,并且在applicationContext.xml引用相应的DTD或XSD(spring1.2引用 的是DTD,spring2.0引用的是XSD),然后会在web.xml中加入这一段(当然,你可以选择用其它方式配置spring对web项目的支 持)。

< listener >
         < listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
</ listener >
< context-param >
       < param-name > contextConfigLocation </ param-name >
       < param-value > /WEB-INF/applicationContext.xml </ param-value >
</ context-param >
3、发布整个项目发部到tomcat上,测试起动服务有没有问题。(一般不会是有问题,我们现在做的只是在axis2这个工程里添加了spring的jar包和在原有的axis2工程的web.xml加上了对spring的支持)。起动没问题的话就访问下http://<host>:<port>/<project name>/services/Version?wsdl,只要成功就可以了,下面进入正题。

4、写一个接口。(体现spring面向接口编程的好处)

package com.hp.bean;
public   interface  MyBean {
     public  String echo();
}
5、实现这个接口。

package com.hp.bean;
public   class  MyBeanImpl implements MyBean {
     public  String echo() {
        
         return   "Merry" ;
    }
}
6、写一个Web Service。

package com.hp.service;
import com.hp.bean.MyBean;
public   class  SpringAwareService {
     private  MyBean myBean;
     public   void  setMyBean(MyBean myBean) {
         this .myBean = myBean;
    }
    
     public  String response(){
        
         return  myBean.echo() +  " Christmas!" ;
    }
}
7、编写applicationContext.xml.(记住第一个bean,也就是applicationContext那个一定要有)

    <bean id= "applicationContext"
         class = "org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"  />
    <bean id= "springAwareService"
         class = "com.hp.service.SpringAwareService" >
        <property name= "myBean"   ref = "myBean"  />
    </bean>
    <bean id= "myBean"   class = "com.hp.bean.MyBeanImpl" ></bean>
8、在WEB-INF/services/下新建一个文件夹,这个名字可以起的随便,我们就起做test吧,然后在WEB-INF/services/test/下建立META-INF这个目录,最后在WEB-INF/services/test/META-INF/下建立service.xml,文件内容是:

<service name= "SpringAwareService" >
    <description>simple spring example</description>
    <parameter name= "ServiceObjectSupplier" >
        org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
    </parameter>
    <parameter name= "SpringBeanName" >springAwareService</parameter>
    <messageReceivers>
        <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-only"
             class = "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"  />
        <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-out"
             class = "org.apache.axis2.rpc.receivers.RPCMessageReceiver"  />
    </messageReceivers>
</service>
这回再发布一下,在没有异常的情况下。访问一下http://<host>:<port>/<project name>/services/SpringAwareService?wsdl 看看
分享到:
评论

相关推荐

    spring和axis 整合

    spring和axis2 整合的小例子, WebContent\axis2-web\listServices.jsp 显示 所有 的 接口

    Spring集成AXIS2的Web_service配置方法

    Spring集成AXIS2的Web_service配置方法

    Axis2 Spring整合POJO开发Web服务

    WebService从零到项目开发使用2——技术研究 源代码

    spring+axis2_xfire整合的webservice

    Web services是建立可互操作的分布式应用程序的新平台。Web service平台是一套标准,它定义了应用程序如何在Web上实现互操作性。你可以用任何你喜欢的语言,在任何...在这里主要介绍两种实现方式:axis2和xfire框架。

    axis2webservice实例。

    axis2整合spring的web开发实例

    发布webService服务接口与spring整合教程

    在网上找了很久的资料,接口已经跟客户对接,特编写了代码文档和附带jar包,并含其他网站的参考地址,注意jdk环境要1.6或以上版本

    通向架构师的道路

    (第十天)之Axis2 Web Service(一) (第十一天)之Axis2 Web Service(二) (第十二天)之Axis2 Web Service(三) (第十三天)Axis2 Web Service安全初步 (第十四天)Axis2 Web Service安全之rampart (第十五天)...

    通向架构师的道路(第1-20天)

    (第十天)之Axis2 Web Service(一) (第十一天)之Axis2 Web Service(二) (第十二天)之Axis2 Web Service(三) (第十三天)Axis2 Web Service安全初步 (第十四天)Axis2 Web Service安全之rampart (第十五天)...

    编程入门_Eclipse教程

    2. Axis2与Eclipse的整合 7 2.1. Axis2下载,并部署axis2到Tomcat 7 2.2. Eclipse下安装Axis2插件 8 2.2.1. 下载axis2的eclipse插件 8 3. 编写Web service程序 10 3.1. Axis2的简单WebService示例 10 3.1.1. 0配置...

    WebServices基础培训视频与源码

    资源名称:WebServices基础培训视频与源码资源目录:【】1.WebService之AXIS即时发布【】10.WebService之创建自己ws站点进行调用操作【】11.WebService之查询数据库操作【】12.使用xfire开发webServie操作不同的数据...

Global site tag (gtag.js) - Google Analytics