【转】使用Apache CXF开发WebServices服务端
原地址:http://cnjava.blog.51cto.com/1208887/335630
在前一篇的博客中,我使用Xfire1.x来开发了WebServies的服务端。
但是如果你访问Apache的官网,可以看到xfire已经被合并了。
最新的框架叫做CXF。
Apache CXF = Celtix + XFire。
CXF 继承了 Celtix 和 XFire 两大开源项目的精华,
提供了对 JAX-WS 全面的支持,并且提供了多种 Binding 、DataBinding、Transport 以及各种 Format 的支持,并且可以根据实际项目的需要,采用代码优先(Code First)或者 WSDL 优先(WSDL First)来轻松地实现 Web Services 的发布和使用。
总之,就是cxf就是好啦。那么接下来我们使用cxf来开发一个webServices的服务端。体验CXF的好处。
环境:MyEclipse6.01+jdk5
1)首先,建一个web工程.
2)写好一个接口和服务类
//服务接口IHelloService.java
1 package com.pengzj.service; 2 3 import java.util.List; 4 5 import javax.jws.WebMethod; 6 import javax.jws.WebService; 7 8 /** 9 * 10 * @author atixujie#gz-accp 11 * 12 */ 13 @WebService 14 public interface IHelloService { 15 16 @WebMethod 17 public String sayHi(String uname); 18 }
//webServices的实现类IHelloServiceImpl .java
1 import com.pengzj.service.IHelloService; 2 3 @WebService 4 public class IHelloServiceImpl implements IHelloService{ 5 6 @Override 7 @WebMethod 8 public String sayHi(String uname) { 9 return "Hello "+uname; 10 } 11 12 }
大家可以注意到,这里用到了webServices的注解。@WebService和@WebMethod.
3)导入CXF的jar包。
到apache的网站上下载CXF的包。
最新的版本是2.2.9 。当然如果你下载这个包就会比较麻烦。因为它需要最新的JDk(1.6.01都不行。要什么1.6.u11)的支持。
所以建议你还是下载2.0.4地址如下:
http://people.apache.org/dist/incubator/cxf/2.0.4-incubator/apache-cxf-2.0.4-incubator.zip
解压之后将lib文件夹下的jar包都复制到项目中。
4)配置CXF。
然后将web.xml的配置文件改成如下:
1 <display-name>cxf</display-name> 2 <description>cxf</description> 3 <servlet> 4 <description>Apache CXF Endpoint</description> 5 <servlet-name>cxf</servlet-name> 6 <servlet-class> 7 org.apache.cxf.transport.servlet.CXFServlet 8 </servlet-class> 9 <load-on-startup>1</load-on-startup> 10 </servlet> 11 12 <servlet-mapping> 13 <servlet-name>cxf</servlet-name> 14 <url-pattern>/services/*</url-pattern> 15 </servlet-mapping> 16 <session-config> 17 <session-timeout>60</session-timeout> 18 </session-config> 19 20 <listener> 21 <listener-class> 22 org.springframework.web.context.ContextLoaderListener 23 </listener-class> 24 </listener>
5)配置Spring的配置文件。
因为CXF集成了Spring。所以以上的配置要默认到WEB-INF/下找spring的配置文件applicationContext.xml。
所以我们要在WEB-INF下建立一个Spring的配置文件applicationContext.xml如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:jaxws="http://cxf.apache.org/jaxws" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 7 http://cxf.apache.org/jaxws 8 http://cxf.apache.org/schemas/jaxws.xsd"> 9 <import resource="classpath:META-INF/cxf/cxf.xml"/> 10 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> 11 <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> 12 <!-- 配置好webservices的类名和服务名 --> 13 <jaxws:endpoint id="hellows" 14 implementor="com.pengzj.service.impl.IHelloServiceImpl" address="/Hellows" /> 15 16 </beans>
准备工作结束了。
部署,运行。在地址上输入:http://localhost:8080/cxfws_0619/services/
就应该可以看到一个超链接,点击可以看到如下的wsdl-xml文件
1 <?xml version="1.0" encoding="utf-8" ?> 2 3 + <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://service.pengzj.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.service.pengzj.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IHelloServiceImplService" targetNamespace="http://impl.service.pengzj.com/">
ok.使用CXF开发服务端大功告成。
总结步骤:
1)建立web工程。导入cxf的jar包。
2)配置web.xml文件
3)配置spring的配置文件。同时配置好服务类的bean.
4)部署运行。
在下一篇中,我们将介绍利用wsdl2java工具生成代码,完成客户端的调用。
转载于:https://www.cnblogs.com/zhengyutao/archive/2012/12/12/2814334.html
【转】使用Apache CXF开发WebServices服务端相关推荐
- cxf restful_使用Apache CXF开发RESTful服务
cxf restful 介绍 如您所知,有两种开发Web服务的方法 简单对象访问协议(SOAP) 代表性状态转移(REST) 在继续学习如何使用Apache CXF创建基于REST的Web服务之前,我 ...
- 使用Apache CXF开发RESTful服务
介绍 如您所知,有两种开发Web服务的方法 简单对象访问协议(SOAP) 代表性状态转移(REST) 在继续学习如何使用Apache CXF创建基于REST的Web服务之前,我们将了解什么是REST. ...
- cxf开发webservice服务端怎么返回固定的报文格式_Spring boot webservice怎么玩? 第277篇...
相关历史文章(阅读本文之前,您可能需要先看下之前的系列?) WebService SOAP概述 - 第275篇 WSDL是什么"Lese" - 第276篇 一.前言 当官不为民做主 ...
- cxf 服务端soap报文_使用Apache CXF开发SOAP Web服务
cxf 服务端soap报文 在上一篇文章中,我逐步介绍了使用apache CXF开发简单的RESTFull服务的步骤. 在本文中,我将讨论使用CXF开发SOAP Web服务. 在继续前进之前,让我们先 ...
- 使用Apache CXF开发SOAP Web服务
在上一篇文章中,我逐步介绍了使用apache CXF开发简单的RESTFull服务的步骤. 在本文中,我将讨论使用CXF开发SOAP Web服务. 在继续前进之前,让我们了解构成SOAP Web服务的 ...
- 使用 CXF 开发 SOAP 服务
转自其它网页,用来记下学习. 今天我们将视角集中在 REST 上,它是继 SOAP 以后,另一种广泛使用的 Web 服务.与 SOAP 不同,REST 并没有 WSDL 的概念,也没有叫做" ...
- java cxf服务端代码_【JAVA】 cxf 生成 webservice 服务端代码
CXF Apache CXF = Celtix + XFire.CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-WS 全面的支持,并且提供了多种 Binding . ...
- C++ 开发SOAP服务端和SOAP客户端
C++ 开发SOAP服务端和SOAP客户端 作者:flyfish 2012-5-12 目的:利用gSOAP自带的Calc例子 仿写一个 网络中使用计算器 客户端通过http发送xml格式的数据请求, ...
- 使用Apache CXF开发REST风格的WebService
使用Apache CXF开发REST风格的WebService REST的概述: REST(表现层状态转化),是一种新的软件架构风格,它以资源为核心,使用http,url,xml以及html等流行协议 ...
最新文章
- JavaScript的方法和技巧
- 劣势者效应下,B站等短视频平台UP主“卖惨”吸睛又吸金?
- 答网友提问:使用 SAP Fiori Tools 创建的 Fiori Elements 应用,如何进行二次开发?
- npm 安装less插件_node+npm+webpack+less安装
- 什么是CSS?你真的理解?
- 探索篇 | 接口字段容错测试(三)
- mysql.data已拥有为,MYSQL LOAD DATA INFILE忽略重复行(自动增量作为主键)
- SpringBoot入门程序HelloWorld
- C/S和B/S和RIA
- SVN下载安装与使用
- java歌词解析器_Java LRC 歌词解析
- dns解析服务器原理,简述DNS服务器原理
- 深度学习----GAN(生成对抗神经网络)原理解析
- sudo 授权需谨慎,否则亲人两行泪!6 个超实用使用技巧
- 天津大学计算机学院2019夏令营,天津大学环境学院2019年全国优秀大学生夏令营顺利举行...
- ubuntu系统学习(1) 测网速命令/实时显示网速speedometer
- html 毛笔书写效果,利用纯SVG+CSS keyframes animation动画实现手写毛笔字(书法)效果...
- 世界儿童日,周大福真诚关爱儿童成长
- 申宝证券-市场呈现出震荡分化走势
- codeblocks下如何修改新建文件的默认代码?