spring与axis2整合发布webservice
最近在研究整合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的更多相关文章
- WebService学习之旅(三)JAX-WS与Spring整合发布WebService
Spring本身就提供了对JAX-WS的支持,有兴趣的读者可以研究下Spring的Spring-WS项目,项目地址: http://docs.spring.io/spring-ws/sites/1.5 ...
- 使用Axis2方式发布webService实例说明
1.简单的pojo方式: 不需要写配置文件,直接把class文件拷贝到axis2的WEB-INF目录下的poji文件夹下即可.但其局限性表现在,实现类不能有包声明,这在实际开发过程中使用较少,这里不做 ...
- spring与cxf整合配置webservice接口(以jaxws:server的方式配置)
ps:最近项目需要跟其他系统做同步,需要使用webservice来提供接口给其他系统调用:临时抱佛脚赶紧去网上找了下资料,发现用Endpoint的方式发布接口好容易哦:赶紧写了个例子做验证,发布成功. ...
- 使用Axis2方式发布webService的三种方式
1.Axis2的下载和安装 首先可以下载如下两个zip包:axis2-1.6.1-bin.zipaxis2-1.6.1-war.zip其中 axis2-1.6.1-bin.zip文件中包含了Axis2 ...
- 13_CXF和Spring整合发布服务
[服务端] 第一步:建立一个Web项目 第二步:填充CXF jar包 第三步:创建接口及服务类 [工程截图(对比之前的WebService_CXF_Server00)] [applicationCon ...
- 使用JDK和axis2发布webservice
最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...
- 使用CXF发布WebService服务简单实例
一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...
- Spring整合CXF之发布WebService服务
今天我们来讲下如何用Spring来整合CXF,来发布WebService服务: 给下官方文档地址:http://cxf.apache.org/docs/writing-a-service-with-s ...
- Spring+CXF整合来管理webservice(服务器启动发布webservice)
Spring+CXF整合来管理webservice 实现步骤: 1. 添加cxf.jar 包(集成了Spring.jar.servlet.jar ),spring.jar包 ,serv ...
随机推荐
- Linux Shell编程(27)——子shell
运行一个shell脚本时会启动另一个命令解释器. 就好像你的命令是在命令行提示下被解释的一样, 类似于批处理文件里的一系列命令.每个shell脚本有效地运行在父shell(parent shell)的 ...
- (转载)不能启动虚拟机 Unable to open kernel device "\\.\Global\vmx86
(转载)http://blog.csdn.net/shenghuiping2001/article/details/7083153 今天系统加了内存条,设置变了一下: 就启动不起虚拟机了,报错: Un ...
- Delphi 6 Web Services初步评估
Delphi 6 Web Services初步评估这是我刚到现在公司的时候(2001年8月份)所作的一份测试报告,现公布出来,希望能对大家有所帮助.因为当时d6刚刚发行,Web Service方面还存 ...
- [Linux&Vim]基础01
学习和使用Linux有一段时间了,作为这么长时间的学习应该是有一定收获的,可惜的是没有一股专研精神,只停留在皮毛. 阅读过一些大牛们学习Linux和Vim的过程,从命令.环境配置.使用个性化设置.编程 ...
- 卡特兰数(Catalan Number) 算法、数论 组合~
Catalan number,卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. 卡特兰数的前几个数 前20项为( ...
- 《图解密码技术》-chaper1-概述
密码和信息安全常识: (1)不要使用保密的密码算法. (2)不要使用低强度密码算法. (3)密码一定会被破解. (4)密码只是信息安全的一部分.
- 部署war包到Tomcat
1. 开发给到一个war包,假设叫 a-b-c.war. 2. 打开Tomcat安装路径 ,假设是“D:\Tomcat\apache-tomcat-7.0.68”,然后进入到 webapps文件夹. ...
- flexpaper 与js 交互
flash 代码//写到要响应的方法体中import flash.external.ExternalInterface;ExternalInterface.call("alert" ...
- JVM分代垃圾回收策略的基础概念
由于不同对象的生命周期不一样,因此在JVM的垃圾回收策略中有分代这一策略.本文介绍了分代策略的目标,如何分代,以及垃圾回收的触发因素. 文章总结了JVM垃圾回收策略为什么要分代,如何分代,以及垃圾回收 ...
- mysql创建数据库(指定编码)
如下脚本创建数据库yourdbname,并制定默认的字符集是utf8. CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 CO ...