1. 开发环境
eclipse,axis2 war,SSH项目
axis2 的eclipse插件:
axis2-eclipse-codegen-wizard.zip 用于生成stub本地代码
axis2-eclipse-service-archiver-wizard.zip 用于发布web service
2. 安装过程
1.下载完2个插件的压缩文件后,可以直接把解压后的文件拷贝到eclipse 的 plugins目录中
从axis2 bin 包里找到:backport-util-concurrent-3.1.jar 和 geronimo-stax-api_1.0_spec-1.0.1.jar
复制到 eclipse\plugins\Axis2_Codegen_Wizard_1.3.0\lib 文件夹下。
backport-util-concurrent-3.1.jar 需要在网上download site:http://www.findjar.com/jar/mule/dependencies/maven2/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar.html
2.修改eclipse\plugins\Axis2_Codegen_Wizard_1.3.0\plugin.xml 文件
在 <runtime> 內加入下面的字串
<library name="lib/geronimo-stax-api_1.0_spec-1.0.1.jar">
<export name="*"/>
</library>
<library name="lib/backport-util-concurrent-3.1.jar">
<export name="*"/>
</library>
3.把Axis2_Codegen_wizard_1.3.0(eclipse/plugins/Axis2_Codegen_wizard_1.3.0)的名字改成Axis2_Codegen_wizard_1.4.0
在plugin.xml中在<plugin>中 把Axis2_Codegen_wizard的version="1.3.0"改成version="1.4.0"
到plugin.xml文件中,保存后重新启动Eclipse即可
3. 开发过程
1.在spring的配置文件里加入:
<bean id= "applicationContext"class ="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
2.在axis2容器里的web.xml加入如下代码,用于加载spring的配置文件,用于初始化bean
<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>
3.目录结构:tomcat/axis2/WEB-INF
项目的配置文件都放在这里
修改配置文件里的一些内容:主要是加载路径相关,eg:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
</bean>
4. 发布服务
aar包里在META-INF里面是
这个aar包里不需要放置类文件,只要一个services.xml用于标识将哪个类发布为服务
文件内容
<service name="student" >
<description>
Please Type your service description here
</description>
<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>
<parameter name= "ServiceObjectSupplier" >
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter> //猜测是spring axis2 结合所需要的 类
<parameter name= "SpringBeanName" >studentservice</parameter>
//发布的服对应的类,因为是利用spring来加载,所以这里必须是spring 配置文件里对应的bean id
//而不能是类的绝对路径,因为需要spring的注入功能所以要从spring窗口里去取得类的实例
</service>
5.向axis2容器里添加项目的Lib包:
注:
axis2可能不支持List<T>这种集合类型,所以要使用对象数组类型来返回多个数据,或者利用String返回,将其在client端进行解析。
So the implementaion will be; public String[] getRes(int a, int b) throws Exception { List list = new ArrayList(); list.add("ddd"); list.add("ddd"); list.add("ddd"); System.out.println(list); return (String[]) list.toArray(new String[list.size()]); } If the method signature returns collections, there is no way for Axis2 to figure out types of the items included in the list, hence you will get an error.