Spring集成axis2

1.新建一个项目,结构如下

2.引入项目所需jar包

axis相关jar文件说明请查阅该博文

3.配置web.xml,注册axis2信息

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5"
 3     xmlns="http://java.sun.com/xml/ns/javaee"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 6     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 7
 8   <display-name>Spring+axis2</display-name>
 9     <!-- 整合spring -->
10     <listener>
11         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
12     </listener>
13      <context-param>
14         <param-name>contextConfigLocation</param-name>
15         <param-value>/WEB-INF/config/appContext*.xml</param-value>
16     </context-param>
17     <!-- 注册axis2的servlet -->
18    <servlet>
19        <servlet-name>AxisServlet</servlet-name>
20        <servlet-class>
21            org.apache.axis2.transport.http.AxisServlet
22        </servlet-class>
23        <load-on-startup>1</load-on-startup>
24    </servlet>
25    <servlet-mapping>
26        <servlet-name>AxisServlet</servlet-name>
27        <url-pattern>/services/*</url-pattern>
28    </servlet-mapping>
29
30
31   <welcome-file-list>
32     <welcome-file>index.jsp</welcome-file>
33   </welcome-file-list>
34 </web-app>

3.创建服务接口

 1 package com.chinawu.service;
 2 /**
 3  *
 4  * @ClassName: IWebService
 5  * @Description: WebService接口类
 6  * @author 吴宇斌
 7  * @date 2014-8-7 下午09:40:19
 8  * @version 1.0
 9  */
10 public interface IWebService {
11     public String welcome();
12     public String getParamName(String str);
13 }

4.创建服务接口实现类

 1 package com.chinawu.service;
 2 /**
 3  *
 4  * @ClassName: WeService
 5  * @Description: WebService实现类
 6  * @author 吴宇斌
 7  * @date 2014-8-7 下午09:41:36
 8  * @version 1.0
 9  */
10 public class WebService implements IWebService{
11
12     public String getParamName(String str) {
13         return "传入参数:"+str;
14     }
15
16     public String welcome() {
17         return "welcome chinaWu!";
18     }
19
20 }

5.创建spring配置文件

1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
3 "http://www.springframework.org/dtd/spring-beans.dtd">
4 <beans>
5     <bean id="webService" class="com.chinawu.service.WebService"></bean>
6 </beans>

6.创建axis配置文件

<?xml version="1.0" encoding="UTF-8"?>
<service name="WebService">
    <description>Spring+axis2</description>
        <parameter name="ServiceClass">
            com.chinawu.service.WebService
        </parameter>
    <parameter name="SpringBeanName">webService</parameter>
    <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>
</service>

7.服务访问

http://localhost/spring2axis/services/WebService?wsdl

8.客户端接口调用

package com.chinawu.client;

import javax.xml.namespace.QName;

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 Client {
     public static void main(String[] args1) throws AxisFault {

            EndpointReference targetEPR = new EndpointReference("http://localhost/spring2axis/services/WebService");
            RPCServiceClient serviceClient = new RPCServiceClient();
            Options options = serviceClient.getOptions();
            options.setTo(targetEPR);

            QName opAddDevice = new QName("http://service.chinawu.com", "welcome");
            Object[] opGetArgs = new Object[] {};
            Class[] returnTypes = new Class[] { String.class };
            Object[] response = serviceClient.invokeBlocking(opAddDevice,opGetArgs, returnTypes);
            String  result = (String)response[0];
            System.out.println("WebService-welcome-reutnInfo:"+result);

            opAddDevice = new QName("http://service.chinawu.com", "getParamName");
            opGetArgs = new Object[] {"你好!"};
            returnTypes = new Class[] { String.class };
            response = serviceClient.invokeBlocking(opAddDevice,opGetArgs, returnTypes);
            result = (String)response[0];
            System.out.println("WebService-getParamName-reutnInfo:"+result);
        }
}

输出结果信息

9.查看服务列表

http://localhost/spring2axis/services/listServices

至此spring成功集成axis,项目源码下载地址: http://pan.baidu.com/s/1gd8BwYn

Spring集成axis2,布布扣,bubuko.com

时间: 2024-10-17 04:57:25

Spring集成axis2的相关文章

axis2+spring集成

转载自:http://www.cnblogs.com/linjiqin/archive/2011/07/05/2098316.html 1.新建一个web project项目,最终工程目录如下: 注意:本文只注重webservice服务器端的开发,因此com.ljq.client和com.ljq.test忽略不计 2.添加所需jar 3.接口HelloWorld package com.ljq.service; public interface HelloWorld { public Strin

RabbitMQ安装和使用(和Spring集成)

一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 Eralng OTP For Windows (vR16B03) 运行安装 Rabbit MQ Server Windows Installer (v3.2.3) 具体操作步骤参考:在 Windows 上安装Rabbit MQ 指南 本人遇到的问题 当安装RabbitMQ后,使用rabbitmqctl

spring集成quartz

spring集成quartz 注意:出现异常"Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class" Spring3.0不支持Quartz2.0,因为org.quartz.CronTrigger在2.0从class变成

Hessian入门(包括与Spring集成)

A.纯Hessian接口开发步骤 Hessian-JAVA服务器端必须具备以下几点: * 1.包含Hessian的jar包(hessian-4.0.37.jar) * 2.设计一个接口,用来给客户端调用(IHessian.java) * 3.实现该接口的功能(IHessianImpl.java) * 4.配置web.xml,配好相应的Servlet(web.xml) * 5.对象必须实现Serializable接口(Foo.java) Hessian-JAVA服务端代码预览图: 1.包含Hess

Struts2+Spring集成合并

前边单独总结了Struts2,Spring和Ibaits框架了,那么怎么结合使用呢?这次先来看一下Sturts2和Spring的集成合并.其实挺简单的,就是导入各自的jar包以及连接彼此的jar包,分好彼此的工作就可以了. 好看一下Struts2+Spring的集成方案!  Struts2和Spring集成有两种方案,是根据action的创建来划分的!  方案一,Struts2负责流程,Spring负责对象的创建:Action由Struts2框架负责创建:Service由Spring框架负责创建

Java Persistence with MyBatis 3(中文版) 第五章 与Spring集成

MyBatis-Spring是MyBatis框架的子模块,用来提供与当前流行的依赖注入框架Spring的无缝集成. Spring框架是一个基于依赖注入(Dependency Injection)和面向切面编程(Aspect Oriented Programming,AOP)的Java框架,鼓励使用基于POJO的编程模型.另外,Spring提供了声明式和编程式的事务管理能力,可以很大程度上简化应用程序的数据访问层(data access layer)的实现.在本章中,我们将看到在基于Spring的

spring集成Log4j以及log4j配置简要说明

Spring集成: web.xml中配置log4j <context-param> <param-name>log4jConfigLocation</param-name> <param-value>WEB-INF/log4j.xml</param-value></context-param> <!-- 加载Spring框架中的log4j监听器Log4jConfigListener --><listener>

rabbitMQ第五篇:Spring集成RabbitMQ

前面几篇讲解了如何使用rabbitMq,这一篇主要讲解spring集成rabbitmq. 首先引入配置文件org.springframework.amqp,如下 <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spring-rabbit</artifactId> <version>1.6.0.RELEASE</version> <

Spring 集成 RMI

Maven <dependency> <groupId>org.springframework</groupId> <artifactId>spring-remoting</artifactId> </dependency> 服务端 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.spri