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整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...
随机推荐
- Android 简单调用摄像头
IDE: android studio3.1.2 界面: activity_main2.xml
- 信用算力基于 RocketMQ 实现金融级数据服务的实践
微服务架构已成为了互联网的热门话题之一,而这也是互联网技术发展的必然阶段.然而,微服务概念的提出者 Martin Fowler 却强调:分布式调用的第一原则就是不要分布式. 纵观微服务实施过程中的弊端 ...
- python3基础概念
数: str:使用单引号或双引号表达,不可变的,一旦创建不可更改,可以使变量赋予不同的字符串,但字符串本身是没有更改的: list:有序的集合,可变的基础数据类型: clear(),copy(),ap ...
- Nginx实现负载均衡的几种方式
负载均衡的几种常用方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. upstream backserver { server 192.168 ...
- Docker部署Jenkins测试环境
安装docker环境 yum install epel-release -y && yum install docker -y 如果是高手需要docker-compose的话就再装个d ...
- nginx常用配置
nginx.conf配置文件详解 其主要分为几个模块 全局快 从开始到events块之间的一部分内容,其作用域为全局作用域 events块 主要负责Nginx服务器与用户的网络连接 常用设置: 是否开 ...
- python安装tesseract
一.最近在学习python爬虫的时候需要用到tesseract,但书上的给的教程对我并不适用,坑了好久天,才终于成功. 二.方法: 1.由于我看的是静谧博主的那本书.他给的教程在python3安装有问 ...
- js获取元素位置和style的兼容性写法
今天说一下js获取元素位置和style的方法.当然不只是element.style那么简单.. 主角:getBoundingClientRect,getClientRects,getComputedS ...
- Qt5应用改变窗口大小时出现黑影
解决方法 在启动程序时,添加-platform wayland参数 添加QT_QPA_PLATFORM=wayland-egl到系统环境变量 注意:改完后虽然没有黑影,但软件图标显示不正常,也不能正常 ...
- ElasticSearch6.5.0 【Rejecting mapping update to [posts] as the final mapping would have more than 1 type】
今天想在一个Index上增加一个type,结果报错 java.lang.IllegalArgumentException: Rejecting mapping update to [posts] as ...