axis 和spring 集成

axis 和spring 集成  有两种方式,关键点式axis 对外暴露的 业务类 和 spring 容器 为我们提供的bean 如何 相互

 

1. 网上有段代码 写了一个 provider="java:SPRINGRPC"   把他写的类导入到工程中,按照下面的方式即可集成成功

 

http://www.99inf.net/SoftwareDev/Java/23450.htm  

 

 

2. 如何吧一个普通的java类发布成webservice 比较简单,可以参考我的附件中的文档,就不说了,现在我们说下使用网上  方法如何集成 axis 和spring  的关键步骤

 

 a. 首先 建立 cn.com.xinli.axis.spring 包 ,将 集成代码全部拷贝进去

 b. 在 applicationContext-webservice.xml 中 配置 集成需要的bean

 

Xml代码
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2.   
  3. < beans   xmlns = "http://www.springframework.org/schema/beans"   
  4.     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   
  5.     xmlns:aop = "http://www.springframework.org/schema/aop"   
  6.     xmlns:tx = "http://www.springframework.org/schema/tx"   
  7.     xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  8.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
  9.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">   
  10.   
  11.     <!-- axis 和spring 集成需要 -->   
  12.     < bean   id = "axissetup"   class = "cn.com.xinli.axis.spring.SpringAxisSetup" >   
  13.     </ bean >   
  14.     <!-- 对外暴露的 webservice 接口 -->   
  15.     < bean   id = "callWebService"   class = "cn.com.xinli.webservice.CallWebService" >   
  16.     </ bean >   
  17.       
  18.       
  19.     <!-- 银行缴费实现  -->   
  20.      < bean   id = "payBank"   class = "cn.com.xinli.webservice.business.impl.PayBankRecive" >     
  21.     </ bean >   
  22.     <!-- 客户服务实现  -->   
  23.      < bean   id = "custService"   class = "cn.com.xinli.webservice.business.impl.CustService" >   
  24.         < property   name = "dataSource"   ref = "dataSource" > </ property >   
  25.     </ bean >   
  26. </ beans >   
<?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:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <!-- axis 和spring 集成需要 -->
    <bean id="axissetup" class="cn.com.xinli.axis.spring.SpringAxisSetup">
    </bean>
    <!-- 对外暴露的 webservice 接口 -->
    <bean id="callWebService" class="cn.com.xinli.webservice.CallWebService">
    </bean>
    
    
	<!-- 银行缴费实现  -->
	 <bean id="payBank" class="cn.com.xinli.webservice.business.impl.PayBankRecive">	
	</bean>
	<!-- 客户服务实现  -->
	 <bean id="custService" class="cn.com.xinli.webservice.business.impl.CustService">
	 	<property name="dataSource" ref="dataSource"></property>
	</bean>
</beans>

 

 c. 在 server-config.wsdd 中增加 对外暴露的service 描述,重点注意 修改className为 springBeanClass,并且加上 springBean 描述

 

 

Xml代码
  1. < service   name = "CallWebService"   provider = "java:SPRINGRPC" >   
  2.   < operation   name = "service"   qname = "ns1:service"   returnQName = "serviceReturn"   returnType = "soapenc:string"   soapAction = ""   xmlns:ns1 = "http://webservice.tdm.xinli.com.cn"   xmlns:soapenc = "http://schemas.xmlsoap.org/soap/encoding/" >   
  3.    < parameter   name = "haader"   type = "soapenc:string" />   
  4.    < parameter   name = "body"   type = "soapenc:string" />   
  5.   </ operation >   
  6.   < parameter   name = "allowedMethods"   value = "service" />   
  7.   < parameter   name = "typeMappingVersion"   value = "1.2" />   
  8.   < parameter   name = "wsdlPortType"   value = "CallWebService" />   
  9.   < parameter   name = "wsdlServicePort"   value = "CallWebService" />   
  10.   < parameter   name = "wsdlTargetNamespace"   value = "urn:CallWebService" />   
  11.   < parameter   name = "springBeanClass"   value = "cn.com.xinli.webservice.CallWebService" />   
  12.   < parameter   name = "springBean"   value = "callWebService" />   
  13.  </ service >   
<service name="CallWebService" provider="java:SPRINGRPC">
  <operation name="service" qname="ns1:service" returnQName="serviceReturn" returnType="soapenc:string" soapAction="" xmlns:ns1="http://webservice.tdm.xinli.com.cn" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <parameter name="haader" type="soapenc:string"/>
   <parameter name="body" type="soapenc:string"/>
  </operation>
  <parameter name="allowedMethods" value="service"/>
  <parameter name="typeMappingVersion" value="1.2"/>
  <parameter name="wsdlPortType" value="CallWebService"/>
  <parameter name="wsdlServicePort" value="CallWebService"/>
  <parameter name="wsdlTargetNamespace" value="urn:CallWebService"/>
  <parameter name="springBeanClass" value="cn.com.xinli.webservice.CallWebService"/>
  <parameter name="springBean" value="callWebService"/>
 </service>

 

d.  我们对外暴露的是 callWebService 这个bean ,如果需要spring 的其他bean ,只需要在 xml中把其他的bean注入到callWebService 这个bean中 然后再 callWebService  这个bean 写上setter方法就OK了!

 

 

现在找到了一中超级简单的方法,axis 和spring 集成的关键在于 axis 对外暴露的方法中如何得到 spring 中的bean

,其实只需要 我们对外 暴漏的类 继承自 ServletEndpointSupport  然后使用

 

Java代码
  1. final  ApplicationContext  applicationContext=getApplicationContext();  
  2. ServiceInterface serviceInterface=(ServiceInterface)applicationContext.getBean(head);  
final ApplicationContext  applicationContext=getApplicationContext();
ServiceInterface serviceInterface=(ServiceInterface)applicationContext.getBean(head);

 

就可以得到bean 了

 

 

 

附件中是整个集成的 例子 和 一个快速发布的 文档(很久以前写的)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值