最近在研究整合spring框架和axis2发布webservice服务,由于本人也才学java不久,为了便于以后的查看,在这里记录下发布过程。

  所需的工具包,spring.jar和axis2链接地址为http://pan.baidu.com/s/1gdgVBoB,这里发布服务只需要两个包,spring-framework-3.2.1.RELEASE-dist.zip和axis2-1.6.2-war.zip。首先解压axis2-1.6.2-war.zip,得到axis2.war文件,放入tomcat的webapps目录中,启动tomcat,浏览器中输入http://ip:端口号/axis2/出现

说明axis2运行成功,会在webapps中生成一个叫axis2的目录。接着在myeclipse中新建一个web工程,这里我取名为WjWebservice,工程目录结构

解压上面的两个包,将其中的jar包全部放入WebRoot/WEB-INF/lib目录中,在WEB-INF目录下新建conf和modules目录,将tomcat的webapps/axis2/WEB-INF下的conf和modules目录中的文件分别倒入在web工程中新建的conf和modules下。新建services目录,新建test(这个目录名字可以自己随便取)目录,新建META-INF目录,新建services.xml。

  在com.wj.service中新建HelloWorld接口,代码为:

package com.wj.service;

public interface HelloWorld {
public String greeting(String name);
public void print();
}

  在com.wj.service中新建HelloWorldImpl类实现HelloWorld接口,代码为:

package com.wj.service;

public class HelloWorldImpl implements HelloWorld{

    public String greeting(String name) {

        return name+"hello world!";
} public void print() {
System.out.println("Hi!"); } }

  在com.wj.service中新建webservice javabean对象HelloWorldService类,代码为:

package com.wj.service;

public class HelloWorldService {
public HelloWorld helloWorld; public HelloWorld getHelloWorld() {
return helloWorld;
} public void setHelloWorld(HelloWorld helloWorld) {
this.helloWorld = helloWorld;
}
public String sayGreeting(String name)
{
return helloWorld.greeting(name);
}
public void sayPrint()
{
helloWorld.print();
}
}

  配置spring的applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean id= "applicationContext" class = "org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
<bean id="helloWorldImpl" class="com.wj.service.HelloWorldImpl">
</bean>
<bean id="helloWorldService" class="com.wj.service.HelloWorldService">
<property name="helloWorld" ref="helloWorldImpl"></property>
</bean>
</beans>

  配置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">
<!-- 注册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>
<!-- 加载spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 增加spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

  配置services.xml:

<?xml version="1.0" encoding="UTF-8"?>
<service name= "helloWorldWebservice" targetNamespace="http://www.wujianjun.org">
<description>simple spring example</description>
<parameter name= "ServiceObjectSupplier" >
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<parameter name= "SpringBeanName" >helloWorldService</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>

  浏览器中输入:http://IP:端口/工程名/services/services.xml配置的服务名称?wsdl生成wsdl文件

到此webservice服务发布完成。

  

spring与axis2整合发布webservice的更多相关文章

  1. WebService学习之旅(三)JAX-WS与Spring整合发布WebService

    Spring本身就提供了对JAX-WS的支持,有兴趣的读者可以研究下Spring的Spring-WS项目,项目地址: http://docs.spring.io/spring-ws/sites/1.5 ...

  2. 使用Axis2方式发布webService实例说明

    1.简单的pojo方式: 不需要写配置文件,直接把class文件拷贝到axis2的WEB-INF目录下的poji文件夹下即可.但其局限性表现在,实现类不能有包声明,这在实际开发过程中使用较少,这里不做 ...

  3. spring与cxf整合配置webservice接口(以jaxws:server的方式配置)

    ps:最近项目需要跟其他系统做同步,需要使用webservice来提供接口给其他系统调用:临时抱佛脚赶紧去网上找了下资料,发现用Endpoint的方式发布接口好容易哦:赶紧写了个例子做验证,发布成功. ...

  4. 使用Axis2方式发布webService的三种方式

    1.Axis2的下载和安装 首先可以下载如下两个zip包:axis2-1.6.1-bin.zipaxis2-1.6.1-war.zip其中 axis2-1.6.1-bin.zip文件中包含了Axis2 ...

  5. 13_CXF和Spring整合发布服务

    [服务端] 第一步:建立一个Web项目 第二步:填充CXF jar包 第三步:创建接口及服务类 [工程截图(对比之前的WebService_CXF_Server00)] [applicationCon ...

  6. 使用JDK和axis2发布webservice

    最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...

  7. 使用CXF发布WebService服务简单实例

    一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...

  8. Spring整合CXF之发布WebService服务

    今天我们来讲下如何用Spring来整合CXF,来发布WebService服务: 给下官方文档地址:http://cxf.apache.org/docs/writing-a-service-with-s ...

  9. Spring+CXF整合来管理webservice(服务器启动发布webservice)

    Spring+CXF整合来管理webservice    实现步骤:      1. 添加cxf.jar 包(集成了Spring.jar.servlet.jar ),spring.jar包 ,serv ...

随机推荐

  1. LINUX系统中动态链接库的创建与使用

    大家都知道,在WINDOWS系统中有很多的动态链接库(以.DLL为后缀的文件,DLL即Dynamic Link Library).这种动态链接库,和静态函数库不同,它里面的函数并不是执行程序本身的一部 ...

  2. (转载)不能启动虚拟机 Unable to open kernel device "\\.\Global\vmx86

    (转载)http://blog.csdn.net/shenghuiping2001/article/details/7083153 今天系统加了内存条,设置变了一下: 就启动不起虚拟机了,报错: Un ...

  3. Poj 2478-Farey Sequence 欧拉函数,素数,线性筛

    Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14291   Accepted: 5647 D ...

  4. C#中同时使用Lambda表达式和递归

    Func<object, int> RTFunc = (RTFuncRT) => { return (RTFuncRT as Func<object, int>)(RTF ...

  5. 【题解】A-B

    [问题描述]出题是一件痛苦的事情!题目看多了也有审美疲劳,于是我舍弃了大家所熟悉的 A+B Problem,改用 A-B 了哈哈!好吧,题目是这样的:给出一串数以及一个数字 C,要求计算出所有 A-B ...

  6. 【设计模式 - 19】之观察者模式(Observer)

    1      模式简介 观察者模式的介绍: 观察者模式定义了对象之间的一对多依赖,这样一来,当一个对象的状态发生改变时,它的所有依赖者都会收到通知并自动更新. 发布者(被观察者) + 订阅者(观察者) ...

  7. 新站上线啦,Html5Think,H5优秀资源的收集、学习、分享和交流

    最近闲来做了个H5资源站,刚刚有点资源,可以访问交流下. 栏目: H5网站模板 H5动画特效 H5资源工具 H5学习资料 致力于H5的学习,通过各个H5优秀案例的学习,逐步完善自己的H5体系,有朝一日 ...

  8. 翻译Android USB HOST API

    翻译Android USB HOST API 源代码地址:http://developer.android.com/guide/topics/connectivity/usb/host.html 译者 ...

  9. Apache SSL服务器配置SSL详解(转)

    1.安装必要的软件 引用 我用的是apahce2.0.61版,可以直接官方提供的绑定openssl的apache. 文件名是:apache_2.0.61-win32-x86-openssl-0.9.7 ...

  10. [转] JavaScript 原型理解与创建对象应用

    这段时间把之前的 JavaScript 的笔记复习了一遍,又学习了一些新的内容,所以把自己的学习笔记加上个人理解在这里总结一下,并提供一个简单的应用示例,希望能帮助一些刚入门的朋友.主 要参考< ...