axis2结合spring发布

本文详细介绍了如何将Java Bean与Spring框架整合到Axis2中,以发布Web服务。通过创建服务组、配置services.xml文件并利用SpringApplicationContext发布Java类,实现了通过HTTP接口调用服务的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 下载axis2  
  2. axis2-1.6.2-war.zip  
  3. 把axis2.war放到tomcat的webapps目录下,启动tomcat,输入http://localhost:9080/axis2 出现后台页面即可。  
  4.   
  5. 结合spring发布axis2  
  6. 一、HelloSpring  
  7. package service;  
  8. public class HelloSpring {  
  9.    public String sayHello(String name){  
  10.       return "你好,"+name;  
  11.    }  
  12.    public String sayGoodMorning(String name){  
  13.        return "早上好,"+name;  
  14.    }  
  15. }  

新建一个目录test,进入目录后,新建META-INF目录,然后在里面新建services.xml

内容如下

[plain]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <serviceGroup>  
  3.    <service name="helloSpring">  
  4.     <description>  
  5.         Spring aware  
  6.     </description>  
  7.     <parameter name="ServiceObjectSupplier">  
  8.         org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier  
  9.     </parameter>  
  10.     <parameter name="SpringBeanName">  
  11.         spring-hello  
  12.     </parameter>  
  13.     <messageReceivers>  
  14.         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"  
  15.             class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />  
  16.     </messageReceivers>  
  17. </service>       
  18.   
  19. </serviceGroup>  

进入test目录,直接运行jar -cvf spring-hello.aar . (注意后面的点)

把生成的aar,复制到%Tomcat%/webapps/axis2/WEB-INF/services目录下。


把HelloSpring.class文件复制到%Tomcat%/webapps/axis2/WEB-INF/classes/service目录中


axis2项目的web.xml,增加

[html]  view plain copy
  1. <listener>  
  2.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  3. </listener>  
  4. <context-param>  
  5.      <param-name>contextConfigLocation</param-name>  
  6.           <param-value>/WEB-INF/applicationContext.xml</param-value>  
  7. </context-param>  

与web.xml同目录新建applicationContext.xml,内容如下

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.         xmlns:aop="http://www.springframework.org/schema/aop"  
  5.         xmlns:tx="http://www.springframework.org/schema/tx"  
  6.         xsi:schemaLocation="  
  7.             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  8.             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  9.             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  10.   <bean id="spring-hello" class="service.HelloSpring"></bean>  
  11. </beans>  

重启tomcat即可。输入http://localhost:9080/axis2 , 击services进入服务列表。
说明:例如spring打包不需要把.class文件打包。

 1. 由JavaBean编译生成的.class文件需要放在WEB-INF\classes目录中,或打成.jar包后放在WEB-INF\lib目录中,而WEB-INF\services目录中的.aar包中不需要包含.class文件,而只需要包含一个META-INF目录,并在该目录中包含一个services.xml文件即可。

2. services.xml的配置方法与前几篇文章的配置方法类似,只是并不需要使用ServiceClass参数指定要发布成WebService的Java类,而是要指定在applicationContext.xml文件中的装配JavaBean的名称(SpringBeanName参数)。

3. 在services.xml文件中需要通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值