Axis2+spring整合实例
来源:互联网 发布:大学生网络借贷 编辑:程序博客网 时间:2024/06/06 03:11
一、下载jar包
axis2-1.6.3下载:
下载地址:http://axis.apache.org/axis2/java/core/download.cgi,
下载axis2-1.6.3-bin.zip,此压缩包包含了所有axis2的jar
spring3.1.4下载我就不废话了
二、创建整合工程并发布测试
1.在搭好的spring MVC框架中,引入axis2的jar
2.在WEB-INF下创建services文件夹,,名字一定是services,其他不能识别,在services一定要再创建一个文件夹(名字顺便,例如:MyService), 在MyService下创建一个文件夹,名字一定是META-INF,在META-INF下创建services.xml文件和一个空的ServiceData.xml,这个名字也是不变的。
最后路径是WEB-INF/services/MyService/META-INF/services.xml services.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?><!-- 访问地址中的访问那个webservice的名字 --><service name="TestWSService"><description>Spring 整合例子 </description><parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><!-- 配置在applicationContext中配置的bean,,这里的值域bean中的id事一样的,否则就报错找不到bean错 --><parameter name="SpringBeanName">testWSService</parameter><messageReceivers><messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /><messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /></messageReceivers></service>
最后目录WEB-INF/services/MyService/META-INF/ServiceData.xmlServiceData.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?><ServiceData> </ServiceData>三、在web.xml中加入以下信息
<!--axis2 WebService配置信息开始--> <servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis2.transport.http.AxisServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping><!-- axis2 WebService配置信息结束-->
四、在applicationContext.xml中注入引用的service
<bean id="testWSService" class="com.usi.jrtx.service.webservice.TestWSService"></bean>
五、TestWSService.java文件
package com.usi.jrtx.service.webservice;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import com.github.miemiedev.mybatis.paginator.domain.Order;import com.github.miemiedev.mybatis.paginator.domain.PageBounds;import com.usi.jrtx.dao.account.AccountMapper;import com.usi.jrtx.model.account.Account;public class TestWSService {@Autowiredprivate AccountMapper accountMapper;/** * 计算減法 d1-d2 */public Integer jianfa(Integer d1, Integer d2) {return d1-d2;}/** * 计算加法 */public Integer jiafa(Integer d1, Integer d2) {PageBounds pageBounds = new PageBounds(1,1000,Order.formString("id.desc"));Account account=new Account();List<Account> list=accountMapper.queryAccounts(account, pageBounds);System.out.println("接收d1:"+d1);System.out.println("接收d2:"+d2);for (int i = 0; i < list.size(); i++) {System.out.println("账户名:"+list.get(i).getAccountName());}return d1+d2;}}
六、客户端使用
package com.usi.jrtx.webservice;import java.util.ArrayList;import java.util.List;import java.util.Random;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;import com.usi.jrtx.model.soap.AccountVO81010;import com.usi.jrtx.model.soap.ConsumeDetail;import com.usi.jrtx.model.soap.ConsumeVO88010;import com.usi.jrwl.util.XMLDomUtil;public class WebserviceTest {/** * 测试 * @throws Exception */public static void my() throws Exception {String url = "http://192.168.20.34:8080/jrtxManager/services/TestWSService?wsdl";try {// 使用RPC方式调用WebServiceRPCServiceClient serviceClient = new RPCServiceClient();// 指定调用WebService的URLEndpointReference targetEPR = new EndpointReference(url);Options options = serviceClient.getOptions();// 确定目标服务地址options.setTo(targetEPR);// 确定调用方法options.setAction("urn:jiafa");options.setTimeOutInMilliSeconds(60000);QName qname = new QName("http://webservice.service.jrtx.usi.com","jiafa");// 指定jiafa方法的参数值String requestContent = "";try {} catch (Exception e) {throw new Exception(e.getMessage(), e.getCause());}Object[] parameters = new Object[] {5,9 };// 指定getPrice方法返回值的数据类型的Class对象Class[] returnTypes = new Class[] { String.class };// 调用方法一 传递参数,调用服务,获取服务返回结果集OMElement element = serviceClient.invokeBlocking(qname, parameters);// 值得注意的是,返回结果就是一段由OMElement对象封装的xml字符串。String result = element.getFirstElement().getText();System.out.println(result);} catch (AxisFault e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {my();}}七、总结:就是那么简单!
1 1
- Axis2+spring整合实例
- Axis2+spring整合实例
- axis2整合spring
- Axis2整合Spring AOP
- Axis2整合spring
- axis2 和spring整合
- webservice axis2+spring整合
- spring与axis2 1.6.2整合
- Axis2在Web项目中整合Spring
- axis2与spring整合遇到的问题
- Axis2在Web项目中整合Spring
- Ehcache整合Spring实例
- Spring 整合Mybatis实例
- hessian spring实例整合
- spring整合kafka实例
- Spring ActiveMQ整合实例
- Axis2与Web项目整合及Axis2在Web项目中整合Spring
- Spring-----Spring整合Struts2实例
- AndroidL 预置APK
- Android自定义View实现验证码
- Core Animation 详解
- Jsp中的自定义标签由浅到深详细讲解
- 通过非聚集索引让select count(*) from 的查询速度提高几十倍、甚至千倍
- Axis2+spring整合实例
- 开发工具下载地址大全
- Redis多机数据库的实现
- 可以展开的方向
- PHP的写时复制
- 模拟GET请求
- 设置样式:字体颜色和背景颜色
- weka cfsSubsetEvalue.java 中文注释
- Android五种数据传递方法汇总