Axis2集成 spring

  1. 创建编写服务接口和方法代码

````
package com.axis2.service;

import org.springframework.stereotype.Service;

@Service
public class HelloWord {
	
	public String getName(String name){
		return name;
	}
	/**
	 * 我在返回列表的时候 axis2 不能处理List。所以用了数组。
	 * 希望找到处理List方法的朋友指点一下。
	 * @param id
	 * @return
	 */
	public String[] getOrderList(String id){
		String[] list = new String[2];
		list[0] = "order1";
		list[1] = "order2";
		return list ;
	}

}
````
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
</span>

创建sevices.xml配置文件

services.xml文件的存放位置在WEB-INF/services/HelloWordService/META-INF/services.xml
<service name="HelloWordService">
	<Description>
		Please Type your service description here
	</Description>
	<messageReceivers>
<span style="white-space:pre">		</span><!-- -->
		<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>
<span style="white-space:pre">	</span><!--使用的注解注入。在这里引用的是spring注入后的默认名称
         SpringBeanName为固定的名称,表示使用Spring中的实例。-->
	<parameter name="SpringBeanName" locked="false">helloWord
	</parameter>
	<!-- Axis2默认会暴露实现类中的所有public方法(如果是用Java实现的)。如果我们把.wsdl文件放到META-INF目录中,而由不希望发布文件中的所有操作,那么我们可以添加excludeOperations标签来排除那些不希望暴露的操作。下面的配置表示只开放了getName接口,在wsdl中只能看见getName方法<span style="font-family: Arial, Helvetica, sans-serif;"> --></span>
	<excludeOperations>

		<!-- <operation>getName</operation> -->
		<operation>getOrderList</operation>
		
	</excludeOperations>
<span style="white-space:pre">	</span><!--服务运行在servlet容器中时,axis2获取<span style="color: rgb(51, 51, 51); font-family: 'Trebuchet MS', Verdana, sans-serif; font-size: 15.04px; line-height: 22.56px;">ServletContext的时候是通过</span><span style="color: rgb(51, 51, 51); font-family: 'Trebuchet MS', Verdana, sans-serif; font-size: 15.04px; line-height: 22.56px; text-align: justify;">SpringAppContextAwareObjectSupplier来获取的。</span>-->
	<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
	</parameter>
</service>

配置spring的application.xml配置文件

<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
	
	<!-- 配置spring需要扫描的包 -->
	<context:component-scan base-package="com.axis2.service" />

	<!-- In case Axis2 can't get a ServletContext, (i.e., uses a different transport 
		or is running Axis2 inside the AAR etc,) you have the option of defining 
		a bean that takes advantage of Spring's internal abilities (ApplicationContextAware 
		interface, specifically) to provide an Application Context to Axis2, with 
		a bean ref 'applicationContext' -->
	<bean id="applicationContext"
		class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
</beans>


配置web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<display-name>HelloWord</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:application.xml</param-value>
	</context-param>
	<listener>
		<description>spring监听器</description>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
	<servlet>
		<description>axis2的提供的实现了Http和Https传输协议的Servlet</description>
		<display-name>Apache-Axis Servlet</display-name>
		<servlet-name>AxisServlet</servlet-name>
		<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet>
		<description>管理发布的服务</description>
		<display-name>Apache-Axis AxisAdmin Servlet (Web Admin)</display-name>
		<servlet-name>AxisAdminServlet</servlet-name>
		<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>
	</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>
	<servlet-mapping>
		<servlet-name>AxisAdminServlet</servlet-name>
		<url-pattern>/axis2-admin/*</url-pattern>
	</servlet-mapping>
	<mime-mapping>
		<extension>inc</extension>
		<mime-type>text/plain</mime-type>
	</mime-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>index.html</welcome-file>
		<welcome-file>/axis2-web/index.jsp</welcome-file>
	</welcome-file-list>
	<error-page>
		<error-code>404</error-code>
		<location>/axis2-web/Error/error404.jsp</location>
	</error-page>
	<error-page>
		<error-code>500</error-code>
		<location>/axis2-web/Error/error500.jsp</location>
	</error-page>
</web-app>
<span style="color:#ff6600;">注意:</span><pre name="code" class="html">org.apache.axis2.webapp.AxisAdminServlet在axis2-1.6.3中没有被加入到jar包中。需要自己在axis2-1.6.3的源码中拷贝到项目中来
具体位置在axis2-1.6.3-src.zip\axis2-1.6.3\modules\webapp\src\main\java\org\apache\axis2\webapp中

最后将axis2-1.6.3-bin.zip解压后的文件中conf文件夹和repository中的modules文件夹拷贝到WEB-INF目录下面。
还可以吧axis2-1.6.3-bin\axis2-1.6.3\webapp中的axis2-web目录考到WEB-INF下面。这样就可以进入web service的管理页面了。(不是必须的)
在conf文件中的axis2.xml文件中可以对web service做一些详细的配置。
最后启动服务器:访问地址  <span style="color:#3333ff;">localhost:8080/HelloWord/services/HelloWordService?wsdl</span>就可以看见我们发布的服务了



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值