使用CXF做webservice整合现有项目的例子
从网上看了很多CXF的资料,大部分都是单独的作为一个webservice项目,对于在现有的spring项目上提供webservice服务的例子基本没有找到。
我做的这个例子是介绍怎么把cxf整合到现有的spring项目中,现在只做到可以传简单的字符串和JAVABEAN,复杂的以后研究。
这是例子的下载地址:一个简单的CXF例子
一,应用cxf应该先把该服务所需要的架包加载进项目中。
对于一个已经搭建好的spring项目,我做的项目中所缺少的架包是
cxf-2.4.3.jar , neethi-3.0.1.jar , wsdl4j-1.6.2.jar , xmlschema-core-2.0.1.jar ,commons-logging-1.1.1.jar ,spring一系列的架包
二,首先是服务接口
- package com.zcz.cxf.service;
- import javax.jws.WebService;
- @WebService
- public interface GreetingService {
- public String greeting(String userName);
- public String say(String eat);
- //public String user(User user);
- }
三,编写服务实现类
- package com.zcz.cxf.service.impl;
- import javax.jws.WebService;
- import com.zcz.cxf.service.GreetingService;
- @WebService
- public class GreetingServiceImpl implements GreetingService {
- public String greeting(String userName){
- return "你好! " + userName;
- }
- public String say(String eat) {
- return "该吃饭了"+eat;
- }
- }
四,配置spring启动时,加载的xml文件,按照下面的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">
- <import resource="classpath:META-INF/cxf/cxf.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
- <jaxws:endpoint id="greetingService"
- implementor="com.gary.test.ws.service.impl.GreetingServiceImpl"
- address="/GreetingService" />
- </beans>
xmlns:jaxws=http://cxf.apache.org/jaxws
http://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="greetingService"implementor="com.gary.test.ws.service.impl.GreetingServiceImpl" address="/GreetingService" />
五,配置web.xml对于webservice的调用,在web.xml中添加以下代码即可
- <servlet>
- <servlet-name>CXFServlet</servlet-name>
- <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>CXFServlet</servlet-name>
- <url-pattern>/cxf/*</url-pattern>
- </servlet-mapping>
六,启动项目如果访问http://localhost:8080/springmvcModel/cxf,出现如下图所示的内容则表示基于cxf的webservice配置成功
七,客户端对于该接口的调用
首先,新建一个与服务器端相同的服务接口类GreetingService
其次,写调用服务的类
- import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
- public class TestGreetingService {
- public static void main(String[] args) {
- //创建WebService客户端代理工厂
- JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
- //注册WebService接口
- factory.setServiceClass(GreetingService.class);
- //设置WebService地址
- factory.setAddress("http://localhost:8080/springmvcModel/cxf/GreetingService");
- GreetingService greetingService = (GreetingService)factory.create();
- System.out.println("开始调用webservice...");
- System.out.println("返回的信息是:"+greetingService.say("米饭"));
- }
- }
配置成功,做完之后发现其实很简单,虽然不明白原理,但是会做基本的应用。
使用CXF做webservice整合现有项目的例子的更多相关文章
- 使用 CXF 做 webservice 简单例子(转载)
使用 CXF 做 webservice 简单例子 Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这 ...
- 使用 CXF 做 webservice 简单例子
Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量 ...
- jfinal集成spring cxf做webservice服务
链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...
- 使用 CXF 做 webservice 简单例子[转]
Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量 ...
- 使用cxf做webservice接口调用
一.服务端 建javaweb工程,去官网下载所需的cxf接口发布的jar包,导入到工程.官网地址:http://cxf.apache.org/download.html 1.建立调用接口 packag ...
- 使用eclipse整合ssh项目的例子--lljf(1)
最近向自己单独做一个基于ssh的项目,来预习和巩固自己的Java基础.找了一个实际生活中的定做衣服的例子来做一做,放到博客上给大家一起分享学习,后边会持续更新项目编写时候遇到的困难和使用的技术等. 1 ...
- CXF之webservice
使用 CXF 做 webservice 简单例子 Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这 ...
- CXF WebService整合SpringMVC的maven项目
首先推荐博客:http://www.cnblogs.com/xdp-gacl/p/4259481.html http://blog.csdn.net/hu_shengyang/article/de ...
- Spring+SpringMVC+Mybatis+Maven+CXF+WebService整合之服务端
WebService服务端项目结构: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...
随机推荐
- C#有关的vshost、exe、config格式说明
vshost.exe.config是程序运行时的配置文本 exe.config是程序运行后会复制到vshost.exe.config app.config是在vshost.exe.config和exe ...
- Ubuntu13.04下Eclipse中文乱码解决
参考:http://www.linuxidc.com/Linux/2011-12/50056.htm baoyu@baoyu:~$ gedit /var/lib/locales/supported.d ...
- otunnel : 一个和lcx差不多的端口转发的工具
项目地址 ooclab/otunnel 下载地址(内涵各大平台) http://dl.ooclab.com/otunnel/ otunnel 用法 前提: 1. 假设 server 的地址为 exam ...
- CPU性能判断指标---上下文切换,运行队列和使用率
http://blog.chinaunix.net/uid-15007890-id-3064254.html uptime11:35:08 up 21:57, 6 users, load aver ...
- python--条件判断和循环--3
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 一.if语句 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄, ...
- ubuntu压缩
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- WPF 自定义命令 以及 命令的启用与禁用
自定义命令: 在WPF中有5个命令类(ApplicationCommands.NavigationCommands.EditingCommands.ComponentCommands 以及 M ...
- 使用Unity制作的一个望远镜特效,在狙击手游戏中非经常见
仅仅须要编写一个脚本文件,然后就能随意设置放大缩小的速度.以及程度.
- MyException--org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ###
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may ...
- swift - 移除界面上的所有元素
下面代码可以遍历移除页面视图上的所有元件: //清空所有子视图 func clearViews() { for v in self.view.subviews as [UIView] { v.remo ...