一、services.xml配置方式:
1、第一种配置方式: 按方法名称进行配置
<operation name="methodName">
<!--表示有参有返回值的方法-->
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<!--表示有参没有返回值的方法-->
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation>
2、第二种配置方式:
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
3、普通类配置:
<service name="serviceName">
<Description>服务的描述</Description>
<parameter name="ServiceClass">全类名</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
4、与Spring集成配置(web工程):
<service name="MySpringService" targetNamespace="http://www.test.org">
<Description>测试spring与axis集成(web工程)</Description>
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<parameter name="SpringBeanName">springBeanName</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
5、与Spring集成配置(JAVA工程):
<service name="MySpringService" targetNamespace="http://www.test.org">
<Description>测试spring与axis集成(web工程)</Description>
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier</parameter>
<parameter name="SpringBeanName">springBeanName</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
二、axis2与Spring集成(Web程序中)
1: 把axis2放入到服务器的发布目录下,把spring.jar放入到/axis2/WEB-INF/lib下.
2: 把axis2中lib下的包引入工程之中(把spring.jar放入到/axis2/WEB-INF/lib下)
axiom-api-1.2.7.jar
axiom-impl-1.2.7.jar
axis2-adb-1.4.1.jar
axis2-kernel-1.4.1.jar
axis2-spring-1.4.1.jar
backport-util-concurrent-3.1.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
neethi-2.0.4.jar
spring.jar
woden-api-1.0M8.jar
woden-impl-dom-1.0M8.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.2.jar
annogen-0.1.0.jar
3: 在web.xml中加入
<!-- spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- webServices -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
4: 编写service类和对应的方法并在applicationContext.xml中进行Bean的配置
5: 在WEB-INF下建services/模板名称/META-INF/services.xml
6: 然后再services.xml中对服务进行配置就可以了,访问:http://localhost:8080/projName/services/serviceName?wsdl就可以访问到对应的服务描述文件了。
三、axis2与Spring集成(JAVA程序中)
1: 把axis2放入到服务器的发布目录下,把spring.jar放入到/axis2/WEB-INF/lib下.
2: 把axis2中lib下的包引入工程之中
axiom-api-1.2.7.jar
axiom-impl-1.2.7.jar
axis2-adb-1.4.1.jar
axis2-kernel-1.4.1.jar
axis2-spring-1.4.1.jar
backport-util-concurrent-3.1.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
neethi-2.0.4.jar
spring.jar
woden-api-1.0M8.jar
woden-impl-dom-1.0M8.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.2.jar
annogen-0.1.0.jar
3: 编写service类和对应的方法并在applicationContext.xml中进行Bean的配置
4:在applicationContext.xml中引入axis2的bean
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" >
<beans>
<bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
</beans>
5: 建立一个初始化spring容器的类(com.test.axis2.java.SpringInit)实现ServiceLifeCycle接口。编写startUp方法如下:
ClassLoader classLoader = service.getClassLoader();
ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}, false);
appCtx.setClassLoader(classLoader);
appCtx.refresh();
6: 在src下建meta-inf/services.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
<service name="MySpringAxis2" class="com.test.axis2.java.SpringInit">
<description>Spring aware</description>
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<parameter name="SpringBeanName">
springService
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
</serviceGroup>
7: 把src下的文件把成jar包后,改名为*.aar 放入/axis2/WEB-INF/services下。
8: 启动服务器,访问http://localhost:8080/projName/services/serviceName?wsdl就可以访问到对应的服务描述文件了。