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 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 描述
<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 然后使用
final ApplicationContext applicationContext=getApplicationContext();
ServiceInterface serviceInterface=(ServiceInterface)applicationContext.getBean(head);
就可以得到bean 了
附件中是整个集成的 例子 和 一个快速发布的 文档(很久以前写的)