webservice-axis2方式 maven + spring

首先建议阅读官方文档http://axis.apache.org/axis2/java/core/docs/spring.html

然后就是实践了

1、maven的pom.xml中关于axis2的配置

[html]  view plain  copy
  1. <dependency>  
  2.             <groupId>org.apache.axis2groupId>  
  3.             <artifactId>axis2-transport-httpartifactId>  
  4.             <version>1.7.2version>  
  5.         dependency>  
  6.         <dependency>  
  7.             <groupId>org.apache.axis2groupId>  
  8.             <artifactId>axis2-springartifactId>  
  9.             <version>1.7.2version>  
  10.         dependency>  
  11.         <dependency>  
  12.             <groupId>org.apache.axis2groupId>  
  13.             <artifactId>axis2artifactId>  
  14.             <version>1.6.2version>  
  15.         dependency>  
  16.         <dependency>  
  17.             <groupId>org.apache.axis2groupId>  
  18.             <artifactId>axis2-transport-localartifactId>  
  19.             <version>1.7.2version>  
  20.         dependency>  
  21.         <dependency>  
  22.             <groupId>org.apache.axis2groupId>  
  23.             <artifactId>axis2-kernelartifactId>  
  24.             <version>1.6.2version>  
  25.         dependency>  

2、编写axis2的对外提供服务的类以及方法(我这里不写接口了,熟悉spring的应该知道最好使用接口以及接口的实现)

我的项目名称是 mavenssh,包路径为com.bestcxx.mavenstu.mavenssh.axis2,类名为Axis2Webservice,方法只有一个叫getStrA

[java]  view plain  copy
  1. package com.bestcxx.mavenstu.mavenssh.axis2;  
  2.   
  3. public class Axis2Webservice {  
  4.       
  5.     public String getStrA(){  
  6.         String str="123";  
  7.         System.out.println("你输入的是:"+str);  
  8.         return str;  
  9.     }  
  10.   
  11. }  


3、spring的applicationContext.xml中将Axis2Webservice注册为bean

[html]  view plain  copy
  1.   
  2.       
  3.      <servlet>    
  4.         <servlet-name>AxisServletservlet-name>      
  5.         <servlet-class>org.apache.axis2.transport.http.AxisServletservlet-class>    
  6.     servlet>   
  7.   
  8.     <servlet-mapping>  
  9.         <servlet-name>AxisServletservlet-name>  
  10.         <url-pattern>/services/*url-pattern>  
  11.     servlet-mapping>  

5、最后是services.xml的编写,这里需要注意路径

比如这里我的项目名称为mavenssh

就需要把services.xml放置到项目的如下路径中

-webapp

  -WEB-INF

    -services

      -mavenssh

        -META-INF

          -services.xml




services.xml的内容为

[html]  view plain  copy
  1. <service name="SpringAwareService">  
  2.     <description>  
  3.         simple spring example  
  4.     description>  
  5.     <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplierparameter>  
  6.     <parameter name="SpringBeanName">springAwareServiceparameter>  
  7.     <parameter name="getStrA">  
  8.    <span style="white-space:pre;">  span> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>  
  9.     parameter>  
  10. service>   


6、这样之后,服务就已经可以正常启动和访问了

http://localhost:8085/mavenssh/services/SpringAwareService?wsdl


7、但是控制台提示

 Please update your axis2.xml file!

只需把我们上面实验的axis2.war中的WEB_INF/conf/下的axis2.xml复制到mavenssh(你的项目)下的WEB_INF目录下即可

里面有个用户名和密码,建议注释掉。



转载请声明出处:http://blog.csdn.net/bestcxx/article/details/53889270

你可能感兴趣的:(系统架构)