这是从axis.apache.org官网上学习的笔记,具体大家可以见 链接
配置与Spring的集成有两种方式,一种是运行在Servlet容器中的模式,另一种就是无需中间件的运行模式。
运行在Servlet容器
首先配置web.xml文件,内容如下
<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>
熟悉spring的人最这一段配置应该不陌生,
接着配置要暴露成WebService的Java类,配置形式跟配置一个spring的bean一样,如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Axis2 Web Service, but to Spring, its just another bean that has dependencies -->
<bean id="springAwareService" class="spring.SpringAwareService">
<property name="myBean" ref="myBean"/>
</bean>
<!-- just another bean / interface with a wired implementation, that's injected by Spring
into the Web Service -->
<bean id="myBean" class="spring.MyBeanImpl">
<property name="val" value="Spring, emerge thyself" />
</bean>
</beans>
接着配置servicex.xml,这个跟往常的配置有点不一样
我们不再需要配置paramter为ServicesClass的配置,取而代之的是parameter为SpringBeanName的属性,属性的value值为我们在spring配置文件中beanId,同时还要增加另外一项属性为parameter 为ServiceObjectSupplier,value值为org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier,具体配置如下:
<service name="SpringAwareService">
<description>
simple spring example
</description>
<!-- ServiceObjectSupplier 配置与spring的集成 -->
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<!-- 配置的value值为在springContext中配置的beanId -->
<parameter name="SpringBeanName">springAwareService</parameter>
<operation name="getValue">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>
具体可以下载我上传的资源下载地址,该工程为maven,解压缩以maven工程的形式导入或者打开。
如果不是运行在servlet容器中的话,services.xml的配置文件需要这么写
<service name="SpringAwareService">
<description>
simple spring example
</description>
<!-- 与servlet容器的区别在于ServiceObjectSupplier的value值 -->
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier</parameter>
<parameter name="SpringBeanName">springAwareService</parameter>
<operation name="getValue">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>