Maven搭建webService (二) 创建服务端---使用web方式发布服务
今天和大家分享 使用 web方式发布 webService 服务端、客户端
1.首先创建 一个web工程(增加Maven依赖)
2.增加Maven依赖包,如下:
<!-- spring core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.5</version>
</dependency> <!-- spring web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.5</version>
</dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<type>pom</type>
</dependency> <dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>xfire</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency> <dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.3</version>
</dependency>
3. 编写HelloWorld 接口类 代码如下:
package net.cc.service; import javax.jws.WebParam;
import javax.jws.WebService; /**
* @author test
* @create 2013-11-26下午10:21:13
*/
@WebService
public interface HelloWorld { String sayHello(@WebParam(name = "userName") String userName); }
说明:
@webService 说明这是一个webService
@webParam 说明参数名称
4. 编写实现类 如下:
package net.cc.service; import javax.jws.WebParam;
import javax.jws.WebService; /**
* @author test
* @create 2013-11-26下午10:22:53
*/
@WebService(serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld { @Override
public String sayHello(@WebParam(name = "userName") String userName) {
// TODO Auto-generated method stub
System.out.println("客户端提交信息: " + userName);
return "say Hello " + userName;
}
}
说明:
@webService(serviceName = “HelloWorld”) 让Apache cxf知道是哪个接口来创建的WSDL
5. 编写spring 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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:endpoint id="ProjectManager" implementor="net.cc.service.HelloWorldImpl"
address="http://192.168.1.105:7890/HelloWorld" /> </beans>
说明:
implementor 表示 实现类 路径
address 表示需要发布的wsdl地址
6.编写 myListener 类 如下:
package net.cc.servlet; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* @author test
* @create 2013-11-26下午10:41:53
*/
public class myListener implements ServletContextListener { @Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub } @Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println("启动Tomcat...");
ClassPathXmlApplicationContext act = new ClassPathXmlApplicationContext(
"/net/cc/service/spring-beans.xml"); } }
说明:
实现 ServletContextListener 目的是为了在Tomcat启动时自动加载
使用 ClassPathXmlApplicationContext 去加载刚才写的 spring-beans.xml 文件
7. 在当前项目中web.xml文件 增加如下代码:
<listener>
<listener-class>net.cc.servlet.myListener</listener-class>
</listener>
说明:
实现 ServletContextListener 接口的类路径
8 tomcat 启动截图:

9 访问web界面 截图:

完成。。。。。。。。。。
Maven搭建webService (二) 创建服务端---使用web方式发布服务的更多相关文章
- Maven搭建webService (一) 创建服务端---使用main函数发布服务
今天和大家分享下 使用maven 搭建 webService 服务端: 首先需要在你的IDE中集成Maven.集成办法此处略....... 1.创建一个web工程. 2.在pom文件中增加以下依赖: ...
- Maven搭建webService (三) 创建客户端---使用Apache CXF方式实现
package test; import net.cc.web.server.HelloWorld; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean ...
- maven搭建webservice apache cxf实现
用 web方式发布 webService 服务端.客户端 一.服务器端搭建 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <project xmlns=& ...
- 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传
一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...
- Wince 6.0适用 .NET 使用HttpRequest的Post上传文件,服务端的Web API接收Post上传上来的文件 代码
//调用的示例 private string fileName = "InStorageData.csv"; string filePath = parentPath + Comm ...
- go语言游戏服务端开发(三)——服务机制
五邑隐侠,本名关健昌,12年游戏生涯. 本教程以Go语言为例. P2P网络为服务进程间.服务进程与客户端间通信提供了便利,在这个基础上可以搭建服务. 在服务层,通信包可以通过定义协议号来确定该包怎 ...
- 【gRPC】C++异步服务端优化版,多服务接口样例
官方的C++异步服务端API样例可读性并不好,理解起来非常的费劲,各种状态机也并不明了,整个运行过程也容易读不懂,因此此处参考网上的博客进行了重写,以求顺利读懂. C++异步服务端实例,详细注释版 g ...
- GPS服务端(上)-Socket服务端(golang)
从第一次写GPS的服务端到现在,已经过去了八年时光.一直是用.net修修改改,从自己写的socket服务,到suppersocket,都是勉强在坚持着,没有真正的稳定过. 最近一段时间,服务端又出了两 ...
- 如何利用cURL和python对服务端和web端进行接口测试
工具描述 cURL是利用URL语法在命令行方式下工作的文件传输工具,是开源爱好者编写维护的免费工具,支持包括Windows.Linux.Mac等数十个操作系统,最新版本为7.27.0,但是我推荐大家使 ...
随机推荐
- FastSocket学习笔记~制定自已的传输协议~续~制定基于FastSocket的协议
FastSocket这个东西上次我已经说过,它使用简单,功能强大,扩展灵活,目前在新浪的生产环境中已经被广泛使用,所以它的性能,安全等各方面我们绝对可以信赖,今天我们来说一个话题,和上一讲有关,这次我 ...
- pop()实现逐个删除数组最后一位并输出
使用pop()循环输出数组的最后一个元素 var a = []; a.push(1);a.push(3.1415926);a.push("number");a.push(" ...
- mplayer-for-windows change color scheme in win 7
Q: When I play movie on Windows7, always comes this message: The color scheme has been changed The f ...
- linux中的namespace
本文将就namespace这个知识点,进行简单的归纳总结,力求通俗易通.在资料汇总的过程中,参考了许多网上的博客资料,在文章尾部给出相关链接. namespace,命名空间,从名字 ...
- 利用rsyslog 对linux 操作进行审计
环境:客户端和服务端都需要安装rsyslog服务 rsyslog server端 cd /etc/rsyslog.d/ cat server.conf $ModLoad imtcp $InputTC ...
- Linux磁盘与文件系统概念理解
磁盘级别概念 这里讲的主要是网上所谓的老式磁盘,它是由一个个盘片组成的,我们先从个盘片结构讲起.如图1所示,图中的一圈圈灰色同心圆为一条条磁道,从圆心向外画直线,可以将磁道划分为若干个弧段,每 ...
- .Net 将一个DataTable分解成多个DataTable
这两天遇到一个问题,我们所接触 的一个系统在导出数据到Excel的时候,产生了内存溢出的错误.原因在于数据过大,它导出是将所有数据存放在一个DataSet的一个表中,再将这个数 据集放入session ...
- 单元测试SimpleTest新手入门
最近学习单元测试,先用了下PHPunit,结果安装问题一大堆,于是立刻放弃改试simpletest,感觉简单多了.下面列出步骤. 1.下载simpletest(版本1.1.0), http://www ...
- CentOS中查看物理CPU信息的方法
1.概念 [1]物理CPU:实际Server中插槽上的CPU个数.物理cpu数量:可以数不重复的 physical id 有几个.[2]逻辑CPULinux用户对 /proc/cpuinfo 这个文件 ...
- 学习php中常用语句与函数
1.while循环多用于不清楚循环次数的情况下,如需要把从数据库中读取出的多条记录(不清楚到底有多少条)并且要根据某个字段的值进行分类,每类值的具体数目,如下图: 其中选项有三种值,对每个值的票数时行 ...