---
title: "axis 和spring 集成"
author: "8366"
date: "2011-01-21T12:26:43Z"
tags: []
categories: ["企业架构"]
slug: "axis-spring"
draft: false
lastmod: "2011-01-21T12:26:43Z"
id: 890751
url: "https://8366.iteye.com/blog/890751"
---

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

 

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

 

[http://www.99inf.net/SoftwareDev/Java/23450.htm](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代码

01. &lt;? xml   version = "1.0"   encoding = "UTF-8" ?&gt;
02. &lt; beans   xmlns = "http://www.springframework.org/schema/beans"
03. xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
04. xmlns:aop = "http://www.springframework.org/schema/aop"
05. xmlns:tx = "http://www.springframework.org/schema/tx"
06. xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
07. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
08. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"&gt;
09. &lt;!-- axis 和spring 集成需要 --&gt;
10. &lt; bean   id = "axissetup"   class = "cn.com.xinli.axis.spring.SpringAxisSetup" &gt;
11. &lt;/ bean &gt;
12. &lt;!-- 对外暴露的 webservice 接口 --&gt;
13. &lt; bean   id = "callWebService"   class = "cn.com.xinli.webservice.CallWebService" &gt;
14. &lt;/ bean &gt;
15. &lt;!-- 银行缴费实现  --&gt;
16. &lt; bean   id = "payBank"   class = "cn.com.xinli.webservice.business.impl.PayBankRecive" &gt;
17. &lt;/ bean &gt;
18. &lt;!-- 客户服务实现  --&gt;
19. &lt; bean   id = "custService"   class = "cn.com.xinli.webservice.business.impl.CustService" &gt;
20. &lt; property   name = "dataSource"   ref = "dataSource" &gt; &lt;/ property &gt;
21. &lt;/ bean &gt;
22. &lt;/ beans &gt;

```
<?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代码

01. &lt; service   name = "CallWebService"   provider = "java:SPRINGRPC" &gt;
02. &lt; 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/" &gt;
03. &lt; parameter   name = "haader"   type = "soapenc:string" /&gt;
04. &lt; parameter   name = "body"   type = "soapenc:string" /&gt;
05. &lt;/ operation &gt;
06. &lt; parameter   name = "allowedMethods"   value = "service" /&gt;
07. &lt; parameter   name = "typeMappingVersion"   value = "1.2" /&gt;
08. &lt; parameter   name = "wsdlPortType"   value = "CallWebService" /&gt;
09. &lt; parameter   name = "wsdlServicePort"   value = "CallWebService" /&gt;
10. &lt; parameter   name = "wsdlTargetNamespace"   value = "urn:CallWebService" /&gt;
11. &lt; parameter   name = "springBeanClass"   value = "cn.com.xinli.webservice.CallWebService" /&gt;
12. &lt; parameter   name = "springBean"   value = "callWebService" /&gt;
13. &lt;/ service &gt;

```
<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 了

 

 

 

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