转载自: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 String greeting(String name);
public String print();
}

4、接口实现类HelloWorldBean

package com.ljq.service;

public class HelloWorldBean implements HelloWorld {
public String greeting(String name) {
return "你好 "+name;
} public String print() {
return "我叫林计钦";
}
}

5、webservice类HelloWorldWebService

package com.ljq.service;

import org.apache.axis2.AxisFault;
import org.apache.axis2.ServiceObjectSupplier;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.i18n.Messages;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; /**
* 可能出现Axis2 spring bean not found 或者 Spring applicationContext not found。
*
* 解决办法:构建自己的ServiceObjectSupplier,实现接口ServiceObjectSupplier,同时也实现Spring的ApplicationContextAware接口
*
*
* @author Administrator
*
*/
public class HelloWorldWebService implements ServiceObjectSupplier,
ApplicationContextAware {
private static ApplicationContext ctx; public Object getServiceObject(AxisService axisService) throws AxisFault {
Parameter springBeanName = axisService.getParameter("SpringBeanName");
String beanName = ((String) springBeanName.getValue()).trim();
if (beanName != null) {
if (ctx == null)
throw new AxisFault("applicationContext is NULL! ");
if (ctx.getBean(beanName) == null)
throw new AxisFault("Axis2 Can't find Spring Bean: " + beanName);
return ctx.getBean(beanName);
} else {
throw new AxisFault(Messages.getMessage("paramIsNotSpecified",
"SERVICE_SPRING_BEANNAME"));
} } public void setApplicationContext(ApplicationContext ctx)
throws BeansException {
this.ctx = ctx;
} }

6、配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 添加spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 加载spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param> <!-- 注册axis2的servlet -->
<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> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

7、在WEB-INF目录下配置applicationContext.xml(不存在则自己创建)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="applicationContext"
class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
<bean id="helloWorld" class="com.ljq.service.HelloWorldBean"></bean>
</beans>

8、在WEB-INF\services\axis\META-INF\目录下配置services.xml(不存在则自己创建)

<?xml version="1.0" encoding="UTF-8"?>
<service name="hwWebService">
<description>axis2与spring集成案例</description>
<!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<!--
SpringBeanName固定的不能改
helloWorld是spring中注册的实现类得id
-->
<parameter name="SpringBeanName">helloWorld</parameter>
<!--
在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。
例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,
而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。
-->
<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>

axis2+spring集成到此已经开发完成,接下把工程部署到tomcat,

然后通过http://localhost:8083/axis2spring/services/hwWebService?wsdl访问

axis2+spring集成的更多相关文章

  1. spring集成环境下的axis webservice的发布,调试

    在spring集成的环境下,无论你是ssh集成,还是ssi集成的情况下,发布webservice往往在调用的时候会出错. 特别是,如果你是这个方式: 将webservice打aar包,放到tomcat ...

  2. 从零开始学 Java - Spring 集成 Memcached 缓存配置(二)

    Memcached 客户端选择 上一篇文章 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)中我们讲到这篇要谈客户端的选择,在 Java 中一般常用的有三个: Memc ...

  3. 从零开始学 Java - Spring 集成 ActiveMQ 配置(一)

    你家小区下面有没有快递柜 近两年来,我们收取快递的方式好像变了,变得我们其实并不需要见到快递小哥也能拿到自己的快递了.对,我说的就是类似快递柜.菜鸟驿站这类的代收点的出现,把我们原来快递小哥必须拿着快 ...

  4. 【转】Dubbo使用例子并且和Spring集成使用

    一.编写客户端和服务器端共用接口类1.登录接口类public interface LoginService {    public User login(String name, String psw ...

  5. 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)

    硬盘和内存的作用是什么 硬盘的作用毫无疑问我们大家都清楚,不就是用来存储数据文件的么?如照片.视频.各种文档或等等,肯定也有你喜欢的某位岛国老师的动作片,这个时候无论我们电脑是否关机重启它们永远在那里 ...

  6. rabbitMQ第五篇:Spring集成RabbitMQ

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

  7. 从零开始学 Java - Spring 集成 ActiveMQ 配置(二)

    从上一篇开始说起 上一篇从零开始学 Java - Spring 集成 ActiveMQ 配置(一)文章中讲了我关于消息队列的思考过程,现在这一篇会讲到 ActivMQ 与 Spring 框架的整合配置 ...

  8. spring集成常用技术的配置

    使用spring集成其他技术,最基本的配置都是模板化的,比如配置视图模板引擎.数据库连接池.orm框架.缓存服务.邮件服务.rpc调用等,以spring的xml配置为例,我将这些配置过程整理出来,并不 ...

  9. Activiti工作流学习(三)Activiti工作流与spring集成

    一.前言 前面Activiti工作流的学习,说明了Activiti的基本应用,在我们开发中可以根据实际的业务参考Activiti的API去更好的理解以及巩固.我们实际的开发中我们基本上都使用sprin ...

随机推荐

  1. BPM配置故事之案例10-获取外部数据

    老李:Hi,小明,我又来了 小明:--这次又怎么了. 老李:之前的物资管理方式太混乱了,这段时间我整理了采购物资清单,现在都录入到我们的ERP中了,以后申请物资改成从ERP数据选择吧.物资明细表我也做 ...

  2. Android之使用文件进行IPC

    一.文件进行IPC介绍 共享文件也是一种不错的进程间通信方式,两个进程通过读/写同一个文件来交换数据.在Windows上,一个文件如果被加了排斥锁将会导致其他线程无法对其进行访问,包括读写,而由于An ...

  3. HotApp小程序服务范围资质查询器

    微信小程序提交审核需要选择资质服务范围,如果服务范围不对,审核会不通过, 开发小程序之前,最好先查询所开发小程序的资质范围,否则无法通过微信审核.   小程序的资质范围查询地址,数据同步微信官方 ht ...

  4. 在MySQL数据库中创建一个完整的表

    1.登陆成功后,首先进入某一个数据库 (不是指数据库服务器) use t1; //t1是数据库名 如图所示: 2.在此数据库中建立数据库表 2.1 先建立表结构(可以理解为表的列名,也就是字段名)在实 ...

  5. Oracle 11g必须开启的服务及服务详细介绍

    转自:http://www.educity.cn/shujuku/404120.html 成功安装Oracle  11g数据库后,你会发现自己电脑运行速度会变慢,配置较低的电脑甚至出现非常卡的状况,通 ...

  6. Struts2.5需要的最少jar文件

    以Struts2.5.2为例 从官网上下载“struts-2.5.2-min-lib.zip”,里面有7个jar文件: commons-fileupload-1.3.2.jarcommons-io-2 ...

  7. 基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#)

    基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#) 为了完美解析GLSL源码,获取其中的信息(都有哪些in/out/uniform等),我决定做个GLSL编译器的前端(以后简称编译器或 ...

  8. Linex 配置php服务器

    此文是可以参考 楼主也不是系统管理员只是迫不得已所以自己才找的  大家可以参考 .... ..... 安装apache 安装mysql 安装PHP 测试服务器 php -v 查询php的版本 就这些了 ...

  9. Laravel 5.3 登录注册底层实现详解

          每个控制器都使用 trait 来引入它们需要的方法 */ 用于处理用户登录认证 用于处理新用户注册 包含重置密码逻辑 用于处理重置密码邮件链接   认证需要的视图 包含了应用的基础布局文件 ...

  10. 修改Coney主题之侧边栏移位

    title: 修改Coney主题之侧边栏移位 date: 2014-12-15 18:09:54 categories: Hexo tags: [hexo,css] --- Coney是一个非常漂亮的 ...