Spring整合axis2
目录
服务端搭建:
第一步:创建maven工程
第二步:完成axis2相关配置
添加axis2的jar包
配置services.xml
配置applicationContext.xml
配置web.xml
第三步:写个服务类
第四步:Tomcat启动工程
客户端测试:
服务端搭建:
第一步:创建maven工程
需要对pom.xml配置spring的相关依赖。对web.xml进行进行简单的配置ok。
这篇文章主要讲axis2的配置,所以就不会详细说这些。
第二步:完成axis2相关配置
添加axis2的jar包
首先要在官网下载axis2
官网:http://axis.apache.org/axis2/java/core/download.cgi
配置services.xml
services.xml的目录结构如下图所示:
在services.xml中,我们要配置发布的webservice的服务。- 关于服务类的配置可以分全类名和指定Spring Bean ID的方式
- 指定spring bean ID
<?xml version="1.0" encoding="UTF-8"?> <service name="UserInfoService"> <!-- 指定服务名,随便定义 --><description>测试axis2webservices</description><!-- 服务的作用说明,可写可不写 --><parameter name="SpringBeanName">userinfo</parameter><parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><messageReceivers><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-out"class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-only"class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></messageReceivers></service>
指定spring bean ID 需要使用org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier获取对应bean id的类路径。
- 全类名
<?xml version="1.0" encoding="UTF-8"?> <service name="UserInfoService"> <!-- 指定服务名,随便定义 --><description>测试axis2webservices</description><!-- 服务的作用说明,可写可不写 --><!-- 指定要发布的类路径 --><parameter name="ServiceClass">com.axis2.UserInfo</parameter><messageReceivers><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-out"class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-only"class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></messageReceivers></service>
- 指定spring bean ID
- 关于发布的方法配置可以不指定发布方法或者指定发布方法。
- 不指定发布的方法:
<?xml version="1.0" encoding="UTF-8"?> <service name="UserInfoService"> <!-- 指定服务名,随便定义 --><description>测试axis2webservices</description><!-- 服务的作用说明,可写可不写 --><parameter name="SpringBeanName">userinfo</parameter><parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><messageReceivers><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-out"class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /><messageReceivermep="http://www.w3.org/2004/08/wsdl/in-only"class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></messageReceivers></service>
- 指定发布方法:
<?xml version="1.0" encoding="UTF-8"?> <service name="UserInfoService"> <!-- 指定服务名,随便定义 --><description>测试axis2webservices</description><!-- 服务的作用说明,可写可不写 --><parameter name="SpringBeanName">userinfo</parameter><parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><operation name="getUserName"><messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /></operation><operation name="addUserHobby"><messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /></operation><operation name="setUserScore"><messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></operation><operation name="print"><messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></operation></service>
- 不指定发布的方法:
配置applicationContext.xml
<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-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"><bean id="userinfo" class="com.axis2.UserInfo"/></beans>
这里注入的bean就是你要发布的服务类。当services.xml使用了SpringBeanName才需要进行的配置。
配置web.xml
<!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><display-name>Archetype Created Web Application</display-name><!-- 加载spring的配置文件 --><context-param> <param-name>contextConfigLocation</param-name><!-- 使用spring bean的方式需要加载注入 --><param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 增加spring监听器 --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet><servlet-name>AxisServlet</servlet-name><servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class><load-on-startup>2</load-on-startup></servlet><!-- 设置dispatchservlet的匹配模式,通过把dispatchservlet映射到/,默认servlet会处理所有的请求,包括静态资源 --><servlet-mapping><servlet-name>AxisServlet</servlet-name><url-pattern>/services/*</url-pattern></servlet-mapping></web-app>
第三步:写个服务类
随便写,也不需要什么注解。注意是否与services.xml中的全类名,方法名对应。applicationContext.xml中是否注入。
package com.axis2;public class UserInfo {public String getUserName() {return "zhangxu";}public String addUserHobby(String like) {return "add hobby "+like;}public void setUserScore(double score) {System.out.println(score);}public void print() {System.out.println("啥都没有");}
}
第四步:Tomcat启动工程
将工程放入Tomcat,启动。在浏览器中输入:
http://localhost:8080/SpringDemo/services/UserInfoService?wsdl
如果能显示xml报文,那么我们的webservice便成功发布了!!!
这里的命名规则是:http://【ip】:【端口】/【工程名】/services/【service名】?wsdl
客户端测试:
package com.axis2;import javax.xml.namespace.QName;import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;public class Test {public static void main(String[] args) {try {String url = "http://localhost:8080/SpringDemo/services/UserInfoService?wsdl";EndpointReference endpointReference = new EndpointReference(url); RPCServiceClient client = new RPCServiceClient(); client.setTargetEPR(endpointReference );Options options = client.getOptions();options.setTo(endpointReference); QName qname = new QName("http://axis2.com", "getUserName"); Object[] param = new Object[]{}; //输入参数比如:"aaa",没有输入,就不写。Class<?>[] types = new Class[]{String.class}; //需要返回类型就是*.class Object[] obj = client.invokeBlocking(qname, param, types); System.out.println(obj[0]);} catch (AxisFault e) {e.printStackTrace();}}
}
这里需要注意两个地方:
String url = "http://localhost:8080/SpringDemo/services/UserInfoService?wsdl";这个就是我们之前输入,并访问到xml的那个地址。
QName中的第一个参数是xs:schema标签的targetNamespace="http://axis2.com",第二个参数对应下面的xs:element 的name,也就是我们发布的方法。
当控制台成功打印,便测试成功。
参考:
Services.xml的讲解 哈根达斯、 http://yangyangcom.iteye.com/blog/2233557
WebService - Axis2与Spring整合并发布多个service(同样使用services.xml) https://blog.csdn.net/J080624/article/details/78444986
官方文档 http://axis.apache.org/axis2/java/core/docs/spring.html
两种服务的发布方式 https://blog.csdn.net/chjttony/article/details/6211478
Spring整合axis2相关推荐
- Strutsw2与Spring整合流程-简述
1. 新建WEB工程: 2. 导入struts2开发包,和资源配置文件 ① globalMessages.properties ② struts.properties 3. ...
- 最新Spring整合MyBatis详解教程
目录 1.导入相关jar包 1. junit 2. mybatis 3. mysql 4. spring相关 5. aop织入 6. mybatis-spring 7. lombok(选用) 2.回顾 ...
- Spring整合Struts2
①导入Struts2 jar包 ②在web.xml文件中创建过滤器 <?xml version="1.0" encoding="UTF-8"?> & ...
- shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决
shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决 from :http://blog.csdn.net/babys/article/ ...
- Spring整合CXF,发布RSETful 风格WebService
这篇文章是承接之前CXF整合Spring的这个项目示例的延伸,所以有很大一部分都是一样的.关于发布CXF WebServer和Spring整合CXF这里就不再多加赘述了.如果你对Spring整合CXF ...
- springMvc+mybatis+spring 整合 包涵整合activiti 基于maven
2019独角兽企业重金招聘Python工程师标准>>> 最近自己独立弄一个activiti项目,写一下整合过程: 环境:jdk1.7 tomcat7.0 maven3.5 ecli ...
- activiti自己定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自己定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自己定义流程之Spr ...
- Spring 整合 Junit
Spring 整合 Junit 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicationContext( ...
- spring整合mybatis(入门级简单教程1)--在spring中配置c3p0,并成功测试
引子:spring整合mybatis.因为,我们看完(我就是这样的)spring和mybatis之后,本想自己写一个小小的项目,以便加深理解,但是我发现在spring中整合mybatis并不是一件容易 ...
- Hibernate Validation与Spring整合各注解的用法Demo
转自:https://www.aliyun.com/jiaocheng/1315650.html <dependency> <groupId>org.hibernate< ...
最新文章
- python zipfile教程_Python模块zipfile原理及使用方法详解
- flutter项目迁移空安全
- 值得推荐的中文版WF/WCF图书
- openresty获取nginx原始的请求头内容
- 《IBM-PC汇编语言程序设计》(第2版)【沈美明 温冬婵】——第七章——自编解析与答案
- 小米和腾讯的.NET笔面试题哪个更难?可自测附答案
- mysql dump 1449_跨版本mysqldump恢复报错Errno1449
- Scala:输入输出
- [转载]ASP.NET-----Repeater数据控件的用法总结
- 证券经营机构信息技术审计实践
- html的header背景图片,关于在HTML插入背景图片的问题
- flink-sql所有语法详解-1.13
- 鸿蒙系统我的二次元之旅,创世神的二次元
- 第6节 远程管理路由器及交换机—基于Cisco Packet Tracer
- cocosCreator 骨骼动画
- Vue # Avoid mutating a prop directly since the value will be overwritten wheneve
- 第一篇 香橙派刷机和开发环境准备(Armbian版)
- 2022细胞生物学实验原理复习资料汇总
- 汇编指令 int 21 h 调用
- PHP检查端口是否可以被绑定
热门文章
- win7_ fiddler 证书安装失败解决方法
- Unraid USB启动盘怎么更换和重新获取注册码密钥?
- No Way Out (Single Version) (Theme From Brother Bear) - Phil Collins 歌词
- 栋的月结 | 第三回合(定期更新、动态、架构、云技术、算法、后端、前端、收听/收看、英文、书籍、影视、好歌、新奇)[含泪总结.. 憋泪分享!]
- hive插入多条数据sql_HIVE sql使用总结
- 【一文学Linux系统基础操作】
- 《游戏设计艺术(第2版)》——所有透镜合集
- 免费开源统计软件介绍——jamovi
- 树莓派设置开机自启动程序
- I8700手机使用感受