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整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...
随机推荐
- 图论杂项细节梳理&模板(虚树,圆方树,仙人掌,欧拉路径,还有。。。)
orzYCB 虚树 %自为风月马前卒巨佬% 用于优化一类树形DP问题. 当状态转移只和树中的某些关键点有关的时候,我们把这些点和它们两两之间的LCA弄出来,以点的祖孙关系连成一棵新的树,这就是虚树. ...
- Hdoj 2109.Fighting for HDU 题解
Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合 ...
- poj1723 SOLDIERS
soldiers真乃神题也! 行列显然可以分开处理. 行好办,显然就是一个货仓选址问题,取中位数即可. 列呢?? ?????? 因为懒得推式子,用不了二分,我决定使用枚举大法!一算复杂度O(n^2), ...
- 在vue中使用import()来代替require.ensure()实现代码打包分离
最近看到一种router的写法 import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) const login = ...
- prototype 与 proto的关系是什么:
__proto__是什么? 我们在这里简单地说下.每个对象都会在其内部初始化一个属性,就是__proto__,当我们访问一个对象的属性 时,如果这个对象内部不存在这个属性,那么他就会去__proto_ ...
- appium desktop 1.7 byName不能用,重写
@Override public WebElement findElementByName(String name){ String string="new UiSelector().tex ...
- selenium官方网站文档,testng官方网站文档
selenium 阅读至grid部分,当前没有远程需求,搁置:https://www.seleniumhq.org/docs/07_selenium_grid.jsp testng http://te ...
- php如何判断数组是一维还是多维
php>4.2 int count ( mixed $var [, int $mode ] ) -- 计算数组中的单元数目或对象中的属性个数 如果可选的 mode 参数设为 COUNT_R ...
- 退回win7后无法上网 的解决方法
如果网卡驱动没问题的话,那你是不是装了360安全卫士,如果装了你打开网络和共享中心———更改适配器设置————右键本地连接———属性————把360局域网防护驱动程序前面的对勾去掉然后确定,一般就能解 ...
- maomao的现在与未来
今晚开始,maomao决定要成为一个和以前不一样的人了. 自从高一开始竞赛生涯以来,我的竞赛就一直处于不是很好,也不是很差的水平,就像我初中一年级到二年级一直处于的状态一样.一直以来,我从来没有对自己 ...