axis2 结合spring 创建 服务端

首先导入axis2和spring所需的jar包,这里不再多说。

其次创建/WEB-INF/services/module-name/META-INF/services.xml(module-name可任意,目录结构需维持成这样)这样的目录结构。

services.xml内容如下

<serviceGroup>
	<!-- 服务名称 -->
	<service name="demoService">
		<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
		<!-- 服务对应的spring bean -->
		<parameter name="SpringBeanName">demoService</parameter>
		<messageReceivers>
			<!--表示有参没有返回值的方法-->
			<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
				class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
			<!--表示有参有返回值的方法-->
			<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
				class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
		</messageReceivers>
		<!--multiple action -->
		<messageReceiver
			class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" /> <!--multiple action -->
	</service>
</serviceGroup>

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>
	
	<!-- axis2 begin -->
	<servlet>
		<servlet-name>AxisServlet</servlet-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>/services/*</url-pattern>
	</servlet-mapping>
	<!-- axis2 end -->

通过访问WSDL可以从http://server-ip-name:port/application-name/services/services-name?wsdl可以得到生成的wsdl。

相关推荐