cxf与spring的整合
cxf与spring的整合:
一:服务端相关配置(配置好后启动tomocat就自动发布了接口,浏览器打开验证下)
1:导入cxf以及spring的相关jar包;
2:在web.xml中增加配置:

代码:
<!--添加cxf配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cxf.xml</param-value>
</context-param>
<!--添加监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--cxf配置-->
<servlet>
<servlet-name>cxfServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<!-- 访问路由配置-->
<servlet-mapping>
<servlet-name>cxfServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
3:cxf文件的配置:
注意:发布的接口和接口的具体实现都要贴上@WebService标签;

spring-cxf.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">
<!--引入源码中的配置文件--> <!--访问地址: http://localhost:8080/ws/product -->
<jaxws:server id="inlineImplementor" serviceClass="com.floor.shop.ws.IProductService"
address="/product">
<jaxws:serviceBean>
<bean class="com.floor.shop.ws.impl.ProductService"/>
</jaxws:serviceBean>
</jaxws:server> </beans>
二:客户端的相关配置:
0.拷贝jar包
1.在cmd中运行wsdl2java "http://localhost:8080/ws/product?wsdl 生成客户端代码
2.在spring配置文件中配置客户信息
在客户端项目的src文件夹下运行dos命令:
wsdl2java +服务端提供的访问接口

2:客户端的 spring-cxf.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"> <!-- 访问地址: http://localhost:8080/ws/product -->
<jaxws:client id="productService" serviceClass="com.floor.shop.ws.IProductService" address="http://localhost:8081/ws/product"/> </beans>
3:客户端中方法的调用:

代码:
ClassPathXmlApplicationContext cxt =
new ClassPathXmlApplicationContext("spring/cxf_Client.xml"); IProductService productService = (IProductService)cxt.getBean("productService");
User user = new User();
user.setUserName("张无忌");
String s = productService.buyProduct(user);
System.out.println("s="+s);
cxf与spring的整合的更多相关文章
- WebService--CXF以及CXF与Spring的整合(jaxws:server形式配置)
前言:好记性不如烂笔头,写博客的好处是,以前接触的东西即便忘记了,也可以从这里查找. Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来 ...
- CXF和spring整合遇到的问题:No bean named 'cxf' is defined
今天在做ws和spring整合的时候,很不幸的遇到了这个问题,百度了好久,竟然没人遇到这个问题,后来谷歌了一下,都是遇到这个问题的了...在看到一篇文章中提到了cxf.xml,所以我果断的打开这个配置 ...
- 【WebService】WebService之CXF和Spring整合(六)
前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...
- Spring boot 整合CXF webservice 遇到的问题及解决
将WebService的WSDL生成的代码的命令: wsimport -p com -s . com http://localhost:8080/service/user?wsdl Spring bo ...
- spring mvc整合mybaitis和log4j
在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...
- WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码)
一.CXF与Spring整合(jaxws:endpoint形式配置) 工具要点:idea.maven 1.新建一个maven项目 <?xml version="1.0" en ...
- struts2 spring mybatis 整合(test)
这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...
- 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】
一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...
- 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)
前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...
随机推荐
- 「ZJOI2016」旅行者 解题报告
「ZJOI2016」旅行者 对网格图进行分治. 每次从中间选一列,然后枚举每个这一列的格子作为起点跑最短路,进入子矩形时把询问划分一下,有点类似整体二分 至于复杂度么,我不会阿 Code: #incl ...
- LOJ#510 北校门外的回忆(找性质+倍增+线段树)
这题一场模拟赛我们出了弱化版(n<=1e6),抄题面给的程序能拿到71分的好成绩 其实后面的29分是加了几个1e9的数据卡人 这糟老头子真是坏得很 正解我们机房看了三天 在这里感谢这篇题解的作者 ...
- A1125. Chain the Ropes
Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...
- 第十一篇- 实现APK打开文件功能
MainActivity.java package com.example.aimee.aimeetest3; import android.content.Context; import andro ...
- plink: 等位型计数(allele count)
对genotype的等位型进行计数,需要用到以下参数: --freq Allele frequencies--counts Modifies --freq to report actual allel ...
- Ubuntu16安装wine(转)
原文:ubuntu16.04安装最新版本的wine 1.安装源 sudo add-apt-repository ppa:wine/wine-builds sudo apt-get update 2.安 ...
- Windows下安装单机Kafka
Zookeeper 解压后进入conf目录,复制出一个zoo.cfg,然后进入bin目录,直接运行zkServer.cmd Kafka 首先你得有一个安装包: 解压,目录结构: config目录里面是 ...
- C语言进阶--DAY3
主要讲解数组和指针有关问题 1. 数组名的本质是一个常量指针 2. 内存编址的最小单位是字节,对于变量来说,一个变量可以取1.2.4.8等字节,对变量取地址来说,取的是低位字节的地址,在32位机中其对 ...
- Android app:transformNativeLibsWithStripDebugSymbolForDebug错误分析
升级NDK解决问题: 先清除 Android/Sdk/ndk-bundle/ 下的内容从 https://developer.android.google.cn/ndk/downloads/older ...
- 快速入门Splay
\(splay\) :伸展树(\(Splay Tree\)),也叫分裂树,是一种二叉排序树,它能在\(O(log n)\)内完成插入.查找和删除操作.它由\(Daniel Sleator\)和\(Ro ...